From 5d8d976fe843af90f06dc9ff48408e96a51a0316 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 5 Oct 2010 08:25:10 +0000 Subject: [PATCH 01/72] Working branch for the socket creator git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3117 e5f2f494-b856-4b98-b285-d166d9295462 From 78533f09dbf43b91578392dc8cee6700b3db7d2b Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 5 Oct 2010 14:55:54 +0000 Subject: [PATCH 02/72] Internal interface of socket creator git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3120 e5f2f494-b856-4b98-b285-d166d9295462 --- configure.ac | 2 + doc/Doxyfile | 4 +- src/bin/Makefile.am | 2 +- src/bin/sockcreator/Makefile.am | 5 ++ src/bin/sockcreator/sockcreator.h | 102 ++++++++++++++++++++++++++ src/bin/sockcreator/tests/Makefile.am | 0 6 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/bin/sockcreator/Makefile.am create mode 100644 src/bin/sockcreator/sockcreator.h create mode 100644 src/bin/sockcreator/tests/Makefile.am diff --git a/configure.ac b/configure.ac index 5947fa4b00..2581e18c16 100644 --- a/configure.ac +++ b/configure.ac @@ -466,6 +466,8 @@ AC_CONFIG_FILES([Makefile src/bin/auth/tests/Makefile src/bin/auth/tests/testdata/Makefile src/bin/auth/benchmarks/Makefile + src/bin/sockcreator/Makefile + src/bin/sockcreator/tests/Makefile src/bin/xfrin/Makefile src/bin/xfrin/tests/Makefile src/bin/xfrout/Makefile diff --git a/doc/Doxyfile b/doc/Doxyfile index be85bf368d..6c52b6606e 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -568,7 +568,9 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = ../src/lib/cc ../src/lib/config ../src/lib/dns ../src/lib/exceptions ../src/lib/datasrc ../src/bin/auth ../src/lib/bench +INPUT = ../src/lib/cc ../src/lib/config ../src/lib/dns \ + ../src/lib/exceptions ../src/lib/datasrc ../src/bin/auth \ + ../src/bin/sockcreator/ ../src/lib/bench # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 1a61ca78be..def75763ee 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -1,4 +1,4 @@ SUBDIRS = bind10 bindctl cfgmgr loadzone msgq host cmdctl auth xfrin xfrout \ - usermgr zonemgr tests + usermgr zonemgr tests sockcreator check-recursive: all-recursive diff --git a/src/bin/sockcreator/Makefile.am b/src/bin/sockcreator/Makefile.am new file mode 100644 index 0000000000..f203aecd6b --- /dev/null +++ b/src/bin/sockcreator/Makefile.am @@ -0,0 +1,5 @@ +SUBDIRS = tests + +pkglibexec_PROGRAMS = b10-sockcreator + +b10_sockcreator_SOURCES = sockcreator.h diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h new file mode 100644 index 0000000000..c98a858b5a --- /dev/null +++ b/src/bin/sockcreator/sockcreator.h @@ -0,0 +1,102 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +/** + * \file sockcreator.h + * \short Socket creator functionality. + * + * This module holds the functionality of the socket creator. It is + * a separate module from main to ease up the tests. + */ + +#ifndef __SOCKCREATOR_H +#define __SOCKCREATOR_H 1 + +#include +#include + +namespace isc { +namespace socket_creator { + +/** + * \short Create a socket and bind it. + * + * This is just a bundle of socket() and bind() calls. The sa_family of + * bind_addr is used to determine the domain of the socket. + * + * \return The file descriptor of the newly created socket, if everything + * goes well. A negative number is returned if an error occurs - + * -1 if the socket() call fails or -2 if bind() fails. In case of error, + * errno is set (or better, left intact from socket() or bind()). + * \param type The type of socket to create (SOCK_STREAM, SOCK_DGRAM, etc). + * \param bind_addr The address to bind. + * \param addrlen The actual length of bind_addr. + */ +int +get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addrlen); + +/** + * Type of the get_sock function, to pass it as parameter. + */ +typedef +int +(*get_sock_t)(const int, struct sockaddr, const socklen_t); + +/** + * Sends a payload socket file descriptor to destination file descriptor. + * This is temporary and it will be stolen somewhere in the surrounding code, + * since it is there already somewhere. + * + * TODO Actually steal it. + */ +int +send_fd(const int destination, const int payload); + +/** + * Type of the send_fd() function, so it can be passed as a parameter. + */ +typedef +int +(*send_fd_t)(const int, const int); + +/** + * \short Infinite loop parsing commands and returning the sockets. + * + * This reads commands and socket descriptions from the input_fd + * file descriptor, creates sockets and writes the results (socket or + * error) to output_fd. + * + * It terminates either if a command asks it to or when unrecoverable + * error happens. + * + * \return Like a return value of a main - 0 means everything OK, anything + * else is error. + * \param input_fd Here is where it reads the commads. + * \param output_fd Here is where it writes the results. + * \param get_sock_fun The function that is used to create the sockets. + * This should be left on the default value, the parameter is here + * for testing purposes. + * \param send_fd_fun The function that is used to send the socket over + * a file descriptor. This should be left on the default value, it is + * here for testing purposes. + */ +int +run(const int input_fd, const int output_fd, + const get_sock_t get_sock_fun = get_sock, + const send_fd_t send_fd_fun = send_fd); + +} +} + +#endif // __SOCKCREATOR_H diff --git a/src/bin/sockcreator/tests/Makefile.am b/src/bin/sockcreator/tests/Makefile.am new file mode 100644 index 0000000000..e69de29bb2 From 7dab055fe9854655b43338485ec8a960dea94080 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 5 Oct 2010 14:56:15 +0000 Subject: [PATCH 03/72] Dummy implementation of the socket creator Only empty functions, so it compiles at last. git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3121 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/Makefile.am | 4 ++- src/bin/sockcreator/main.cc | 11 +++++++++ src/bin/sockcreator/sockcreator.cc | 39 ++++++++++++++++++++++++++++++ src/bin/sockcreator/sockcreator.h | 8 +++--- 4 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/bin/sockcreator/main.cc create mode 100644 src/bin/sockcreator/sockcreator.cc diff --git a/src/bin/sockcreator/Makefile.am b/src/bin/sockcreator/Makefile.am index f203aecd6b..f69c7f93c5 100644 --- a/src/bin/sockcreator/Makefile.am +++ b/src/bin/sockcreator/Makefile.am @@ -1,5 +1,7 @@ SUBDIRS = tests +CLEANFILES = *.gcno *.gcda + pkglibexec_PROGRAMS = b10-sockcreator -b10_sockcreator_SOURCES = sockcreator.h +b10_sockcreator_SOURCES = sockcreator.cc sockcreator.h main.cc diff --git a/src/bin/sockcreator/main.cc b/src/bin/sockcreator/main.cc new file mode 100644 index 0000000000..0acba52e03 --- /dev/null +++ b/src/bin/sockcreator/main.cc @@ -0,0 +1,11 @@ +#include "sockcreator.h" + +using namespace isc::socket_creator; + +int main() { + /* + * TODO Maybe use some OS-specific caps interface and drop everything + * but ability to bind ports? It would be nice. + */ + return run(0, 1); // Read commands from stdin, output to stdout +} diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc new file mode 100644 index 0000000000..6ca3da2303 --- /dev/null +++ b/src/bin/sockcreator/sockcreator.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include "sockcreator.h" + +namespace isc { +namespace socket_creator { + +int +get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len) +{ + // TODO Implement +} + +int +send_fd(const int destination, const int payload) { + // TODO Steal +} + +int +run(const int input_fd, const int output_fd, const get_sock_t get_sock, + const send_fd_t send_fd) +{ + // TODO Implement +} + +} // End of the namespaces +} diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h index c98a858b5a..c97fe17c0a 100644 --- a/src/bin/sockcreator/sockcreator.h +++ b/src/bin/sockcreator/sockcreator.h @@ -41,17 +41,17 @@ namespace socket_creator { * errno is set (or better, left intact from socket() or bind()). * \param type The type of socket to create (SOCK_STREAM, SOCK_DGRAM, etc). * \param bind_addr The address to bind. - * \param addrlen The actual length of bind_addr. + * \param addr_len The actual length of bind_addr. */ int -get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addrlen); +get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len); /** * Type of the get_sock function, to pass it as parameter. */ typedef int -(*get_sock_t)(const int, struct sockaddr, const socklen_t); +(*get_sock_t)(const int, struct sockaddr *, const socklen_t); /** * Sends a payload socket file descriptor to destination file descriptor. @@ -96,7 +96,7 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock_fun = get_sock, const send_fd_t send_fd_fun = send_fd); -} +} // End of the namespaces } #endif // __SOCKCREATOR_H From 3772748aa192829099877ac1c1e43e43b691df16 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 5 Oct 2010 14:56:47 +0000 Subject: [PATCH 04/72] Description and protocol of the sock creator git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3122 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/README | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/sockcreator/README diff --git a/src/bin/sockcreator/README b/src/bin/sockcreator/README new file mode 100644 index 0000000000..8dd9cbbc58 --- /dev/null +++ b/src/bin/sockcreator/README @@ -0,0 +1,36 @@ +The socket creator +================== + +The only thing we need higher rights than standard user is binding sockets to +ports lower than 1024. So we will have a separate process that keeps the +rights, while the rests drop them for security reasons. + +This process is the socket creator. Its goal is to be as simple as possible +and to contain as little code as possible to minimise the amount of code +running with higher privileges (to minimize the number of bugs and make +checking/auditing it easier). It uses low-level OS API instead of some +fancy library for that reason. It has only fixed-length reads so there's no +place for buffer overruns. + +Protocol +-------- + +It talks with whoever started it by its stdin/stdout. It reads simple +binary protocol from stdin and does what the commands ask. Command is a single +byte (usually from the printable range, so it is easier to debug and guess +what it does), followed by parameters. + +* 'T': It has no parameters. It asks the socket creator to terminate. + +* 'S' 'U|T' '4|6' port address: Asks it to create a port. First parameter + tels the socket type (either UDP or TCP). The second one is address family + (either IPv4 or IPv6). Then there's 2 bytes of the port number, in the + network byte order. The last one is either 4 or 16 bytes of address, as + they would be passed to bind (note that both parameters are already prepared, + like hton called on them). + + The answer to this is either 'S' and then the socket is passed using sendmsg + if it is successful. If it fails, 'E' is returned, followed by either + 'S' or 'B' (either socket() or bind() call failed). Then there is one int + (architecture-dependent length and endianess), which is the errno value + after the failure. From 3b1fef1e85522e061114beb6bd9013a51da16c08 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Fri, 8 Oct 2010 18:06:29 +0000 Subject: [PATCH 05/72] README git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3145 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/README | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bin/sockcreator/README b/src/bin/sockcreator/README index 8dd9cbbc58..d32cff3966 100644 --- a/src/bin/sockcreator/README +++ b/src/bin/sockcreator/README @@ -34,3 +34,13 @@ what it does), followed by parameters. 'S' or 'B' (either socket() or bind() call failed). Then there is one int (architecture-dependent length and endianess), which is the errno value after the failure. + +The creator may also send these messages at any time (but not in the middle +of another message): + +* 'F': A fatal error has been detected. It is followed by one byte of error + condition code and then the creator terminates with non-zero status. + + The conditions are: + * 'I': Invalid input (eg. someone sent a wrong letter and it does not + understand it). From 0add6c7b1047219eda3f1d7fa13340da61cd96b5 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Fri, 8 Oct 2010 18:07:17 +0000 Subject: [PATCH 06/72] Tests for the get_sock function git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3146 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/main.cc | 17 ++- src/bin/sockcreator/tests/Makefile.am | 15 +++ src/bin/sockcreator/tests/run_unittests.cc | 22 ++++ .../sockcreator/tests/sockcreator_tests.cc | 111 ++++++++++++++++++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 src/bin/sockcreator/tests/run_unittests.cc create mode 100644 src/bin/sockcreator/tests/sockcreator_tests.cc diff --git a/src/bin/sockcreator/main.cc b/src/bin/sockcreator/main.cc index 0acba52e03..09ee3cbc72 100644 --- a/src/bin/sockcreator/main.cc +++ b/src/bin/sockcreator/main.cc @@ -1,8 +1,23 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + #include "sockcreator.h" using namespace isc::socket_creator; -int main() { +int +main() { /* * TODO Maybe use some OS-specific caps interface and drop everything * but ability to bind ports? It would be nice. diff --git a/src/bin/sockcreator/tests/Makefile.am b/src/bin/sockcreator/tests/Makefile.am index e69de29bb2..b630a402cc 100644 --- a/src/bin/sockcreator/tests/Makefile.am +++ b/src/bin/sockcreator/tests/Makefile.am @@ -0,0 +1,15 @@ +CLEANFILES = *.gcno *.gcda + +TESTS = +if HAVE_GTEST +TESTS += run_unittests +run_unittests_SOURCES = ../sockcreator.cc ../sockcreator.h +run_unittests_SOURCES += sockcreator_tests.cc +run_unittests_SOURCES += run_unittests.cc + +run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) +run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) +run_unittests_LDADD = $(GTEST_LDADD) +endif + +noinst_PROGRAMS = $(TESTS) diff --git a/src/bin/sockcreator/tests/run_unittests.cc b/src/bin/sockcreator/tests/run_unittests.cc new file mode 100644 index 0000000000..74c27b2ba5 --- /dev/null +++ b/src/bin/sockcreator/tests/run_unittests.cc @@ -0,0 +1,22 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include + +int +main(int argc, char *argv[]) { + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc new file mode 100644 index 0000000000..496b319e56 --- /dev/null +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -0,0 +1,111 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include "../sockcreator.h" + +#include +#include +#include +#include +#include +#include + +using namespace isc::socket_creator; + +namespace { + +/* + * Generic version of the creation of socket test. It just tries to + * create the socket and checks the result is not negative (eg. + * it is valid descriptor) and that it can listen. + * + * This is a macro so ASSERT_* does abort the TEST, not just the + * function inside. + */ +#define TEST_ANY_CREATE(SOCK_TYPE, ADDR_TYPE, ADDR_FAMILY, ADDR_SET, \ + CHECK_SOCK) \ + do { \ + /* + * This should create an address that binds on all interfaces + * and lets the OS choose a free port. + */ \ + struct ADDR_TYPE addr; \ + memset(&addr, 0, sizeof addr); \ + ADDR_SET(addr); \ + struct sockaddr *addr_ptr = static_cast( \ + static_cast(&addr)); \ + addr_ptr->sa_family = ADDR_FAMILY; \ + \ + int socket = get_sock(SOCK_TYPE, addr_ptr, sizeof addr); \ + /* Provide even nice error message. */ \ + ASSERT_GE(socket, 0) << "Couldn't create a socket of type " \ + #SOCK_TYPE " and family " #ADDR_FAMILY ", failed with " \ + << socket << " and errno " << errno; \ + CHECK_SOCK(ADDR_TYPE, socket); \ + EXPECT_EQ(0, close(socket)); \ + } while(0) + +// Just helper macros +#define INADDR_SET(WHAT) do { WHAT.sin_addr.s_addr = INADDR_ANY; } while(0) +#define IN6ADDR_SET(WHAT) do { WHAT.sin6_addr = in6addr_any; } while(0) +// If the get_sock returned something useful, listen must work +#define TCP_CHECK(UNUSED, SOCKET) do { \ + EXPECT_EQ(0, listen(SOCKET, 1)); \ + } while(0) +// More complicated with UDP, so we send a packet to ourselfs and se if it +// arrives +#define UDP_CHECK(ADDR_TYPE, SOCKET) do { \ + struct ADDR_TYPE addr; \ + memset(&addr, 0, sizeof addr); \ + struct sockaddr *addr_ptr = static_cast( \ + static_cast(&addr)); \ + \ + socklen_t len = sizeof addr; \ + ASSERT_EQ(0, getsockname(SOCKET, addr_ptr, &len)); \ + ASSERT_EQ(5, sendto(SOCKET, "test", 5, 0, addr_ptr, sizeof addr)); \ + char buffer[5]; \ + ASSERT_EQ(5, recv(SOCKET, buffer, 5, 0)); \ + EXPECT_STREQ("test", buffer); \ + } while(0) + +/* + * Several tests to ensure we can create the sockets. + */ +TEST(get_sock, udp4_create) { + TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in, AF_INET, INADDR_SET, UDP_CHECK); +} + +TEST(get_sock, tcp4_create) { + TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in, AF_INET, INADDR_SET, TCP_CHECK); +} + +TEST(get_sock, udp6_create) { + TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in6, AF_INET6, IN6ADDR_SET, + UDP_CHECK); +} + +TEST(get_sock, tcp6_create) { + TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in6, AF_INET6, IN6ADDR_SET, + TCP_CHECK); +} + +/* + * Try to ask the get_sock function some nonsense and test if it + * is able to report error. + */ +TEST(get_sock, fail_with_nonsense) { + ASSERT_LT(get_sock(0, NULL, 0), 0); +} + +} From 1f7ffbad521f059f611876c27d8373f355ca8c40 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Fri, 8 Oct 2010 18:07:34 +0000 Subject: [PATCH 07/72] Read and write wrappers To be able to live without short reads. Needed by tests as well. git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3147 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/sockcreator.cc | 45 ++++++++++++++++++++++++++++++ src/bin/sockcreator/sockcreator.h | 32 +++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index 6ca3da2303..685c5e5f0b 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -14,6 +14,9 @@ #include "sockcreator.h" +#include +#include + namespace isc { namespace socket_creator { @@ -35,5 +38,47 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock, // TODO Implement } +bool +write_data(const int fd, const char *buffer, const size_t length) { + size_t rest(length); + // Just keep writing until all is written + while(rest) { + ssize_t written(write(fd, buffer, rest)); + if(rest == -1) { + if(errno == EINTR) { // Just keep going + continue; + } else { + return false; + } + } else { // Wrote something + rest -= written; + buffer += written; + } + } + return true; +} + +ssize_t +read_data(const int fd, char *buffer, const size_t length) { + size_t rest(length), already(0); + while(rest) { // Stil something to read + ssize_t amount(read(fd, buffer, rest)); + if(rest == -1) { + if(errno == EINTR) { // Continue on interrupted call + continue; + } else { + return -1; + } + } else if(amount) { + already += amount; + rest -= amount; + buffer += amount; + } else { // EOF + return already; + } + } + return already; +} + } // End of the namespaces } diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h index c97fe17c0a..b708d9b093 100644 --- a/src/bin/sockcreator/sockcreator.h +++ b/src/bin/sockcreator/sockcreator.h @@ -96,6 +96,38 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock_fun = get_sock, const send_fd_t send_fd_fun = send_fd); +/* + * \short write() that writes everything. + * Wrapper around write(). The difference is, it never writes less data + * and looks successfull (eg. it blocks until all data are written). + * Retries on signals. + * + * \return True if sucessfull, false otherwise. The errno variable is left + * intact. + * \param fd Where to write. + * \param data The buffer to write. + * \param length How much data is there to write. + * + * TODO: Shouldn't this be in some kind of library? + */ +bool +write_data(const int fd, const char *data, const size_t length); + +/* + * \short read() that reads everything. + * Wrapper around read(). It does not do short reads, if it returns less, + * it means there was EOF. It retries on signals. + * + * \return Number of bytes read or -1 on error. + * \param fd Where to read data from. + * \param data Where to put the data. + * \param length How many of them. + * + * TODO: Shouldn't this be in some kind of library? + */ +ssize_t +read_data(const int fd, char *buffer, const size_t length); + } // End of the namespaces } From 6b09fa3b6e19b73f82940664802158baaca0297d Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Fri, 8 Oct 2010 18:07:54 +0000 Subject: [PATCH 08/72] Tests for run git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3148 e5f2f494-b856-4b98-b285-d166d9295462 --- .../sockcreator/tests/sockcreator_tests.cc | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index 496b319e56..39311ac67f 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -17,8 +17,12 @@ #include #include #include +#include +#include #include +#include #include +#include #include using namespace isc::socket_creator; @@ -108,4 +112,216 @@ TEST(get_sock, fail_with_nonsense) { ASSERT_LT(get_sock(0, NULL, 0), 0); } +/* + * This creates a pipe, forks and feeds the pipe with given data. + * Used to provide the input in non-blocking/asynchronous way. + */ +pid_t +provide_input(int *read_pipe, const char *input, const size_t length) { + int pipes[2]; + if(pipe(pipes)) { + return -1; + } + *read_pipe = pipes[0]; + pid_t pid(fork()); + if(pid) { // We are in the parent + return pid; + } else { // This is in the child, just puth the data there + close(pipes[0]); + if(!write_data(pipes[1], input, length)) { + exit(1); + } else { + close(pipes[1]); + exit(0); + } + } +} + +/* + * This creates a pipe, forks and reads the pipe and compares it + * with given data. Used to check output of run in asynchronous way. + */ +pid_t +check_output(int *write_pipe, const char *output, const size_t length) { + int pipes[2]; + if(pipe(pipes)) { + return -1; + } + *write_pipe = pipes[1]; + pid_t pid(fork()); + if(pid) { // We are in parent + return pid; + } else { + close(pipes[1]); + char buffer[length + 1]; + // Try to read one byte more to see if the output ends here + if(read_data(pipes[0], buffer, length + 1) != length) + exit(1); + // Normalize the return value - return 0 on equality, 1 on nonequality + exit(!!memcmp(buffer, output, length)); + } +} + +/* + * Waits for pid to terminate and checks it terminates successfully (with 0). + */ +bool +process_ok(pid_t process) { + int status; + // Make sure it does terminate when the output is shorter than expected + /* + * FIXME: if the timeout is reached, this kill the whole test, not just + * the waitpid call. Should have signal handler. This is no show-stopper, + * but we might have another tests to run. + */ + alarm(3); + if(waitpid(process, &status, 0) == -1) { + if(errno == EINTR) + kill(process, SIGTERM); + return false; + } + return WIFEXITED(status) && WEXITSTATUS(status) == 0; +} + +/* + * Helper functions to pass to run during testing. + */ +int +get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t addr_len) +{ + int result(0); + int port; + /* + * We encode the type and address family into the int and return it. + * Lets ignore the port and address for now + * First bit is 1 if it is known type. Second tells if TCP or UDP. + * The familly is similar - third bit is known address family, + * the fourth is the family. + */ + switch(type) { + case SOCK_STREAM: + result += 1; + break; + case SOCK_DGRAM: + result += 3; + break; + } + switch(addr->sa_family) { + case AF_INET: + result += 4; + port = static_cast( + static_cast(addr))->sin_port; + break; + case AF_INET6: + result += 12; + port = static_cast( + static_cast(addr))->sin6_port; + break; + } + /* + * The port should be 0xffff. If it's not, we change the result. + * The port of 0xbbbb means bind should fail and 0xcccc means + * socket should fail. + */ + if(port != 0xffff) { + errno = 0; + if(port == 0xbbbb) { + return -2; + } else if(port == 0xcccc) { + return -1; + } else { + result += 16; + } + } + return result; +} + +int +send_fd_dummy(const int destination, const int what) +{ + /* + * Make sure it is 1 byte so we know the length. We do not use more during + * the test anyway. + */ + char fd_data(what); + if(!write_data(destination, &fd_data, 1)) + return -1; +} + +/* + * Generic test that it works, with various inputs and outputs. + * It uses different functions to create the socket and send it and pass + * data to it and check it returns correct data back, to see if the run() + * parses the commands correctly. + */ +void run_test(const char *input_data, const size_t input_size, + const char *output_data, const size_t output_size, + bool should_succeed = true) +{ + // Prepare the input feeder and output checker processes + int input_fd, output_fd; + pid_t input(provide_input(&input_fd, input_data, input_size)), + output(check_output(&output_fd, output_data, output_size)); + ASSERT_NE(-1, input) << "Couldn't start input feeder"; + ASSERT_NE(-1, output) << "Couldn't start output checker"; + // Run the body + int result(run(input_fd, output_fd, get_sock_dummy, send_fd_dummy)); + if(should_succeed) { + EXPECT_EQ(0, result); + } else { + EXPECT_NE(0, result); + } + // Check the subprocesses say everything is OK too + EXPECT_TRUE(process_ok(input)); + EXPECT_TRUE(process_ok(output)); +} + +/* + * Check it terminates successfully when asked to. + */ +TEST(run, terminate) { + run_test("T", 1, NULL, 0); +} + +/* + * Check it rejects incorrect input. + */ +TEST(run, bad_input) { + run_test("XXX", 3, "FI", 2, false); +} + +/* + * Check it correctly parses queries to create sockets. + */ +TEST(run, sockets) { + run_test( + "SU4\xff\xff\0\0\0\0" // This has 9 bytes + "ST4\xff\xff\0\0\0\0" // This has 9 bytes + "ST6\xff\xff\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" // This has 21 bytes + "SU6\xff\xff\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" // This has 21 bytes + "T", 61, + "S\x07S\x05S\x0dS\x0f", 8); +} + +/* + * Check if failures of get_socket are handled correctly. + */ +TEST(run, bad_sockets) { + // We need to construct the answer, but it depends on int length. + size_t int_len(sizeof(int)); + size_t result_len(4 + 2 * int_len); + char result[result_len]; + // Both errno parts should be 0 + memset(result, 0, result_len); + // Fill the 2 control parts + strcpy(result, "EB"); + strcpy(result + 2 + int_len, "ES"); + // Run the test + run_test( + "SU4\xbb\xbb\0\0\0\0" + "SU4\xcc\xcc\0\0\0\0" + "T", 19, + result, result_len); +} + } From d58451bac9dd51a562a24032d013e1eacc5a3fde Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Sun, 10 Oct 2010 08:01:33 +0000 Subject: [PATCH 09/72] Implemented get_sock And fixed a test. It seems underlaying bind does not like passing NULL pointer as address and kills program with sigterm. git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3159 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/sockcreator.cc | 9 ++++++++- src/bin/sockcreator/tests/sockcreator_tests.cc | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index 685c5e5f0b..5c991bed85 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -23,7 +23,14 @@ namespace socket_creator { int get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len) { - // TODO Implement + int sock(socket(bind_addr->sa_family, type, 0)); + if(sock == -1) { + return -1; + } + if(bind(sock, bind_addr, addr_len) == -1) { + return -2; + } + return sock; } int diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index 39311ac67f..42e9f19ac8 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -109,7 +109,9 @@ TEST(get_sock, tcp6_create) { * is able to report error. */ TEST(get_sock, fail_with_nonsense) { - ASSERT_LT(get_sock(0, NULL, 0), 0); + struct sockaddr addr; + memset(&addr, 0, sizeof addr); + ASSERT_LT(get_sock(0, &addr, sizeof addr), 0); } /* From be4ec3ec23084ca94e72a60ddb1a2d4250ade5cd Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Sun, 10 Oct 2010 08:02:12 +0000 Subject: [PATCH 10/72] Code style correction The rest of code seems to have space between if/while and the parenthesis. git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3160 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/sockcreator.cc | 18 ++++----- src/bin/sockcreator/sockcreator.h | 5 +++ .../sockcreator/tests/sockcreator_tests.cc | 40 +++++++++---------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index 5c991bed85..09cff18de5 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -24,10 +24,10 @@ int get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len) { int sock(socket(bind_addr->sa_family, type, 0)); - if(sock == -1) { + if (sock == -1) { return -1; } - if(bind(sock, bind_addr, addr_len) == -1) { + if (bind(sock, bind_addr, addr_len) == -1) { return -2; } return sock; @@ -49,10 +49,10 @@ bool write_data(const int fd, const char *buffer, const size_t length) { size_t rest(length); // Just keep writing until all is written - while(rest) { + while (rest) { ssize_t written(write(fd, buffer, rest)); - if(rest == -1) { - if(errno == EINTR) { // Just keep going + if (rest == -1) { + if (errno == EINTR) { // Just keep going continue; } else { return false; @@ -68,15 +68,15 @@ write_data(const int fd, const char *buffer, const size_t length) { ssize_t read_data(const int fd, char *buffer, const size_t length) { size_t rest(length), already(0); - while(rest) { // Stil something to read + while (rest) { // Stil something to read ssize_t amount(read(fd, buffer, rest)); - if(rest == -1) { - if(errno == EINTR) { // Continue on interrupted call + if (rest == -1) { + if (errno == EINTR) { // Continue on interrupted call continue; } else { return -1; } - } else if(amount) { + } else if (amount) { already += amount; rest -= amount; buffer += amount; diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h index b708d9b093..d28aa71d7e 100644 --- a/src/bin/sockcreator/sockcreator.h +++ b/src/bin/sockcreator/sockcreator.h @@ -77,6 +77,11 @@ int * file descriptor, creates sockets and writes the results (socket or * error) to output_fd. * + * Current errors are: + * - 1: Read error + * - 2: Write error + * - 3: Protocol error (unknown command, etc) + * * It terminates either if a command asks it to or when unrecoverable * error happens. * diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index 42e9f19ac8..ee106da922 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -58,15 +58,15 @@ namespace { << socket << " and errno " << errno; \ CHECK_SOCK(ADDR_TYPE, socket); \ EXPECT_EQ(0, close(socket)); \ - } while(0) + } while (0) // Just helper macros -#define INADDR_SET(WHAT) do { WHAT.sin_addr.s_addr = INADDR_ANY; } while(0) -#define IN6ADDR_SET(WHAT) do { WHAT.sin6_addr = in6addr_any; } while(0) +#define INADDR_SET(WHAT) do { WHAT.sin_addr.s_addr = INADDR_ANY; } while (0) +#define IN6ADDR_SET(WHAT) do { WHAT.sin6_addr = in6addr_any; } while (0) // If the get_sock returned something useful, listen must work #define TCP_CHECK(UNUSED, SOCKET) do { \ EXPECT_EQ(0, listen(SOCKET, 1)); \ - } while(0) + } while (0) // More complicated with UDP, so we send a packet to ourselfs and se if it // arrives #define UDP_CHECK(ADDR_TYPE, SOCKET) do { \ @@ -81,7 +81,7 @@ namespace { char buffer[5]; \ ASSERT_EQ(5, recv(SOCKET, buffer, 5, 0)); \ EXPECT_STREQ("test", buffer); \ - } while(0) + } while (0) /* * Several tests to ensure we can create the sockets. @@ -121,16 +121,16 @@ TEST(get_sock, fail_with_nonsense) { pid_t provide_input(int *read_pipe, const char *input, const size_t length) { int pipes[2]; - if(pipe(pipes)) { + if (pipe(pipes)) { return -1; } *read_pipe = pipes[0]; pid_t pid(fork()); - if(pid) { // We are in the parent + if (pid) { // We are in the parent return pid; } else { // This is in the child, just puth the data there close(pipes[0]); - if(!write_data(pipes[1], input, length)) { + if (!write_data(pipes[1], input, length)) { exit(1); } else { close(pipes[1]); @@ -146,18 +146,18 @@ provide_input(int *read_pipe, const char *input, const size_t length) { pid_t check_output(int *write_pipe, const char *output, const size_t length) { int pipes[2]; - if(pipe(pipes)) { + if (pipe(pipes)) { return -1; } *write_pipe = pipes[1]; pid_t pid(fork()); - if(pid) { // We are in parent + if (pid) { // We are in parent return pid; } else { close(pipes[1]); char buffer[length + 1]; // Try to read one byte more to see if the output ends here - if(read_data(pipes[0], buffer, length + 1) != length) + if (read_data(pipes[0], buffer, length + 1) != length) exit(1); // Normalize the return value - return 0 on equality, 1 on nonequality exit(!!memcmp(buffer, output, length)); @@ -177,8 +177,8 @@ process_ok(pid_t process) { * but we might have another tests to run. */ alarm(3); - if(waitpid(process, &status, 0) == -1) { - if(errno == EINTR) + if (waitpid(process, &status, 0) == -1) { + if (errno == EINTR) kill(process, SIGTERM); return false; } @@ -200,7 +200,7 @@ get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t addr_len) * The familly is similar - third bit is known address family, * the fourth is the family. */ - switch(type) { + switch (type) { case SOCK_STREAM: result += 1; break; @@ -208,7 +208,7 @@ get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t addr_len) result += 3; break; } - switch(addr->sa_family) { + switch (addr->sa_family) { case AF_INET: result += 4; port = static_cast( @@ -225,11 +225,11 @@ get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t addr_len) * The port of 0xbbbb means bind should fail and 0xcccc means * socket should fail. */ - if(port != 0xffff) { + if (port != 0xffff) { errno = 0; - if(port == 0xbbbb) { + if (port == 0xbbbb) { return -2; - } else if(port == 0xcccc) { + } else if (port == 0xcccc) { return -1; } else { result += 16; @@ -246,7 +246,7 @@ send_fd_dummy(const int destination, const int what) * the test anyway. */ char fd_data(what); - if(!write_data(destination, &fd_data, 1)) + if (!write_data(destination, &fd_data, 1)) return -1; } @@ -268,7 +268,7 @@ void run_test(const char *input_data, const size_t input_size, ASSERT_NE(-1, output) << "Couldn't start output checker"; // Run the body int result(run(input_fd, output_fd, get_sock_dummy, send_fd_dummy)); - if(should_succeed) { + if (should_succeed) { EXPECT_EQ(0, result); } else { EXPECT_NE(0, result); From 26b876a067e285be526793254f9422067a89e071 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Sun, 10 Oct 2010 08:02:30 +0000 Subject: [PATCH 11/72] Fix the run tests git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3161 e5f2f494-b856-4b98-b285-d166d9295462 --- .../sockcreator/tests/sockcreator_tests.cc | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index ee106da922..8040a29433 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -24,6 +24,7 @@ #include #include #include +#include using namespace isc::socket_creator; @@ -157,10 +158,28 @@ check_output(int *write_pipe, const char *output, const size_t length) { close(pipes[1]); char buffer[length + 1]; // Try to read one byte more to see if the output ends here - if (read_data(pipes[0], buffer, length + 1) != length) + size_t got_length(read_data(pipes[0], buffer, length + 1)); + bool ok(true); + if (got_length != length) { + fprintf(stderr, "Different length (expected %u, got %u)\n", + static_cast(length), + static_cast(got_length)); + ok = false; + } + if(!ok || memcmp(buffer, output, length)) { + // If the differ, print what we have + for(size_t i(0); i != got_length; ++ i) { + fprintf(stderr, "%02hhx", buffer[i]); + } + fprintf(stderr, "\n"); + for(size_t i(0); i != length; ++ i) { + fprintf(stderr, "%02hhx", output[i]); + } + fprintf(stderr, "\n"); exit(1); - // Normalize the return value - return 0 on equality, 1 on nonequality - exit(!!memcmp(buffer, output, length)); + } else { + exit(0); + } } } @@ -268,6 +287,10 @@ void run_test(const char *input_data, const size_t input_size, ASSERT_NE(-1, output) << "Couldn't start output checker"; // Run the body int result(run(input_fd, output_fd, get_sock_dummy, send_fd_dummy)); + // Close the pipes + close(input_fd); + close(output_fd); + // Did it run well? if (should_succeed) { EXPECT_EQ(0, result); } else { From 66bb0f76db68b8f96fc4ac819f9c07c7f8a404e6 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Sun, 10 Oct 2010 08:02:42 +0000 Subject: [PATCH 12/72] The run function git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3162 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/sockcreator.cc | 102 ++++++++++++++++++++++++++++- src/bin/sockcreator/sockcreator.h | 1 + 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index 09cff18de5..6a7335d593 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -16,6 +16,10 @@ #include #include +#include +#include +#include +#include namespace isc { namespace socket_creator { @@ -42,7 +46,103 @@ int run(const int input_fd, const int output_fd, const get_sock_t get_sock, const send_fd_t send_fd) { - // TODO Implement +// These are macros so they can exit the function +#define READ(WHERE, HOW_MANY) do { \ + size_t how_many = (HOW_MANY); \ + if (read_data(input_fd, (WHERE), how_many) < how_many) { \ + return 1; \ + } \ + } while (0) +#define WRITE(WHAT, HOW_MANY) do { \ + size_t how_many = (HOW_MANY); \ + if (!write_data(output_fd, (WHAT), (HOW_MANY))) { \ + return 2; \ + } \ + } while (0) +#define DEFAULT \ + default: /* Unrecognized part of protocol */ \ + WRITE("FI", 2); \ + return 3; + for (;;) { + // Read the command + char command; + READ(&command, 1); + switch (command) { + case 'T': // The "terminate" command + return 0; + case 'S': { // Create a socket + // Read what type of socket they want + char type[2]; + READ(type, 2); + // Read the address they ask for + struct sockaddr *addr(NULL); + size_t addr_len(0); + struct sockaddr_in addr_in; + struct sockaddr_in6 addr_in6; + switch (type[1]) { // The address family + /* + * Here are some casts. They are required by C++ and + * the low-level interface (they are implicit in C). + */ + case '4': + addr = static_cast( + static_cast(&addr_in)); + addr_len = sizeof addr_in; + memset(&addr_in, 0, sizeof addr_in); + addr_in.sin_family = AF_INET; + READ(static_cast(static_cast( + &addr_in.sin_port)), 2); + READ(static_cast(static_cast( + &addr_in.sin_addr.s_addr)), 4); + break; + case '6': + addr = static_cast( + static_cast(&addr_in6)); + addr_len = sizeof addr_in6; + memset(&addr_in6, 0, sizeof addr_in6); + addr_in6.sin6_family = AF_INET6; + READ(static_cast(static_cast( + &addr_in6.sin6_port)), 2); + READ(static_cast(static_cast( + &addr_in6.sin6_addr.s6_addr)), 16); + break; + DEFAULT + } + int sock_type; + switch (type[0]) { // Translate the type + case 'T': + sock_type = SOCK_STREAM; + break; + case 'U': + sock_type = SOCK_DGRAM; + break; + DEFAULT + } + int result(get_sock(sock_type, addr, addr_len)); + if (result >= 0) { // We got the socket + WRITE("S", 1); + send_fd(output_fd, result); + } else { + WRITE("E", 1); + switch (result) { + case -1: + WRITE("S", 1); + break; + case -2: + WRITE("B", 1); + break; + default: + return 4; + } + int error(errno); + WRITE(static_cast(static_cast(&error)), + sizeof error); + } + break; + } + DEFAULT + } + } } bool diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h index d28aa71d7e..a76d748614 100644 --- a/src/bin/sockcreator/sockcreator.h +++ b/src/bin/sockcreator/sockcreator.h @@ -81,6 +81,7 @@ int * - 1: Read error * - 2: Write error * - 3: Protocol error (unknown command, etc) + * - 4: Some internal inconsistency detected * * It terminates either if a command asks it to or when unrecoverable * error happens. From 8da3cbf0ec4fcd563b8e779038a38811a77dece8 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Sun, 10 Oct 2010 11:31:32 +0000 Subject: [PATCH 13/72] Cleanups and library splitting * Some of the code might be useful in other places, so it is split into libraries (isc::util::io and isc::util::unittests). * Fixing flags in the sockcreator, leading to new warnings, fixing these warnings. * TODO: read_data and write_data were tested implicitly with run(), but as they moved out to other library, they should have their own testcase. git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3163 e5f2f494-b856-4b98-b285-d166d9295462 --- configure.ac | 3 + src/bin/sockcreator/Makefile.am | 11 ++ src/bin/sockcreator/sockcreator.cc | 52 +------ src/bin/sockcreator/sockcreator.h | 32 ---- src/bin/sockcreator/tests/Makefile.am | 15 ++ .../sockcreator/tests/sockcreator_tests.cc | 109 ++------------ src/lib/Makefile.am | 2 +- src/lib/util/Makefile.am | 1 + src/lib/util/io/Makefile.am | 6 + src/lib/util/io/fd.cc | 68 +++++++++ src/lib/util/io/fd.h | 61 ++++++++ src/lib/util/unittests/Makefile.am | 7 + src/lib/util/unittests/README | 5 + src/lib/util/unittests/fork.cc | 137 ++++++++++++++++++ src/lib/util/unittests/fork.h | 52 +++++++ 15 files changed, 386 insertions(+), 175 deletions(-) create mode 100644 src/lib/util/Makefile.am create mode 100644 src/lib/util/io/Makefile.am create mode 100644 src/lib/util/io/fd.cc create mode 100644 src/lib/util/io/fd.h create mode 100644 src/lib/util/unittests/Makefile.am create mode 100644 src/lib/util/unittests/README create mode 100644 src/lib/util/unittests/fork.cc create mode 100644 src/lib/util/unittests/fork.h diff --git a/configure.ac b/configure.ac index 2581e18c16..f34f2fb1da 100644 --- a/configure.ac +++ b/configure.ac @@ -508,6 +508,9 @@ AC_CONFIG_FILES([Makefile src/lib/datasrc/Makefile src/lib/datasrc/tests/Makefile src/lib/xfr/Makefile + src/lib/util/Makefile + src/lib/util/io/Makefile + src/lib/util/unittests/Makefile ]) AC_OUTPUT([src/bin/cfgmgr/b10-cfgmgr.py src/bin/cfgmgr/tests/b10-cfgmgr_test.py diff --git a/src/bin/sockcreator/Makefile.am b/src/bin/sockcreator/Makefile.am index f69c7f93c5..1ac46401f2 100644 --- a/src/bin/sockcreator/Makefile.am +++ b/src/bin/sockcreator/Makefile.am @@ -1,7 +1,18 @@ SUBDIRS = tests +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib + +AM_CXXFLAGS = $(B10_CXXFLAGS) + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +pkglibexecdir = $(libexecdir)/@PACKAGE@ + CLEANFILES = *.gcno *.gcda pkglibexec_PROGRAMS = b10-sockcreator b10_sockcreator_SOURCES = sockcreator.cc sockcreator.h main.cc +b10_sockcreator_LDADD = $(top_builddir)/src/lib/util/io/libutil_io.la diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index 6a7335d593..f35b5cb121 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -14,6 +14,8 @@ #include "sockcreator.h" +#include + #include #include #include @@ -21,6 +23,8 @@ #include #include +using namespace isc::util::io; + namespace isc { namespace socket_creator { @@ -38,8 +42,8 @@ get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len) } int -send_fd(const int destination, const int payload) { - // TODO Steal +send_fd(const int, const int) { + return 0; } int @@ -54,7 +58,6 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock, } \ } while (0) #define WRITE(WHAT, HOW_MANY) do { \ - size_t how_many = (HOW_MANY); \ if (!write_data(output_fd, (WHAT), (HOW_MANY))) { \ return 2; \ } \ @@ -121,6 +124,7 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock, int result(get_sock(sock_type, addr, addr_len)); if (result >= 0) { // We got the socket WRITE("S", 1); + // FIXME: Check the output and write a test for it send_fd(output_fd, result); } else { WRITE("E", 1); @@ -145,47 +149,5 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock, } } -bool -write_data(const int fd, const char *buffer, const size_t length) { - size_t rest(length); - // Just keep writing until all is written - while (rest) { - ssize_t written(write(fd, buffer, rest)); - if (rest == -1) { - if (errno == EINTR) { // Just keep going - continue; - } else { - return false; - } - } else { // Wrote something - rest -= written; - buffer += written; - } - } - return true; -} - -ssize_t -read_data(const int fd, char *buffer, const size_t length) { - size_t rest(length), already(0); - while (rest) { // Stil something to read - ssize_t amount(read(fd, buffer, rest)); - if (rest == -1) { - if (errno == EINTR) { // Continue on interrupted call - continue; - } else { - return -1; - } - } else if (amount) { - already += amount; - rest -= amount; - buffer += amount; - } else { // EOF - return already; - } - } - return already; -} - } // End of the namespaces } diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h index a76d748614..a88a746c4f 100644 --- a/src/bin/sockcreator/sockcreator.h +++ b/src/bin/sockcreator/sockcreator.h @@ -102,38 +102,6 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock_fun = get_sock, const send_fd_t send_fd_fun = send_fd); -/* - * \short write() that writes everything. - * Wrapper around write(). The difference is, it never writes less data - * and looks successfull (eg. it blocks until all data are written). - * Retries on signals. - * - * \return True if sucessfull, false otherwise. The errno variable is left - * intact. - * \param fd Where to write. - * \param data The buffer to write. - * \param length How much data is there to write. - * - * TODO: Shouldn't this be in some kind of library? - */ -bool -write_data(const int fd, const char *data, const size_t length); - -/* - * \short read() that reads everything. - * Wrapper around read(). It does not do short reads, if it returns less, - * it means there was EOF. It retries on signals. - * - * \return Number of bytes read or -1 on error. - * \param fd Where to read data from. - * \param data Where to put the data. - * \param length How many of them. - * - * TODO: Shouldn't this be in some kind of library? - */ -ssize_t -read_data(const int fd, char *buffer, const size_t length); - } // End of the namespaces } diff --git a/src/bin/sockcreator/tests/Makefile.am b/src/bin/sockcreator/tests/Makefile.am index b630a402cc..41d7e835c5 100644 --- a/src/bin/sockcreator/tests/Makefile.am +++ b/src/bin/sockcreator/tests/Makefile.am @@ -1,5 +1,17 @@ CLEANFILES = *.gcno *.gcda +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +# This is here because of juggling with sockaddr pointer. +# It is somehow required by the BSD socket interface, but it +# breaks C++ strict aliasing rules, so we need to ask the compiler +# not to use them. +AM_CPPFLAGS += -fno-strict-aliasing +AM_CXXFLAGS = $(B10_CXXFLAGS) + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + TESTS = if HAVE_GTEST TESTS += run_unittests @@ -10,6 +22,9 @@ run_unittests_SOURCES += run_unittests.cc run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) run_unittests_LDADD = $(GTEST_LDADD) +run_unittests_LDADD += $(top_builddir)/src/lib/util/io/libutil_io.la +run_unittests_LDADD += \ + $(top_builddir)/src/lib/util/unittests/libutil_unittests.la endif noinst_PROGRAMS = $(TESTS) diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index 8040a29433..bdedf19c1d 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -14,19 +14,20 @@ #include "../sockcreator.h" +#include +#include + #include #include #include -#include -#include #include #include #include -#include #include -#include using namespace isc::socket_creator; +using namespace isc::util::unittests; +using namespace isc::util::io; namespace { @@ -115,103 +116,14 @@ TEST(get_sock, fail_with_nonsense) { ASSERT_LT(get_sock(0, &addr, sizeof addr), 0); } -/* - * This creates a pipe, forks and feeds the pipe with given data. - * Used to provide the input in non-blocking/asynchronous way. - */ -pid_t -provide_input(int *read_pipe, const char *input, const size_t length) { - int pipes[2]; - if (pipe(pipes)) { - return -1; - } - *read_pipe = pipes[0]; - pid_t pid(fork()); - if (pid) { // We are in the parent - return pid; - } else { // This is in the child, just puth the data there - close(pipes[0]); - if (!write_data(pipes[1], input, length)) { - exit(1); - } else { - close(pipes[1]); - exit(0); - } - } -} - -/* - * This creates a pipe, forks and reads the pipe and compares it - * with given data. Used to check output of run in asynchronous way. - */ -pid_t -check_output(int *write_pipe, const char *output, const size_t length) { - int pipes[2]; - if (pipe(pipes)) { - return -1; - } - *write_pipe = pipes[1]; - pid_t pid(fork()); - if (pid) { // We are in parent - return pid; - } else { - close(pipes[1]); - char buffer[length + 1]; - // Try to read one byte more to see if the output ends here - size_t got_length(read_data(pipes[0], buffer, length + 1)); - bool ok(true); - if (got_length != length) { - fprintf(stderr, "Different length (expected %u, got %u)\n", - static_cast(length), - static_cast(got_length)); - ok = false; - } - if(!ok || memcmp(buffer, output, length)) { - // If the differ, print what we have - for(size_t i(0); i != got_length; ++ i) { - fprintf(stderr, "%02hhx", buffer[i]); - } - fprintf(stderr, "\n"); - for(size_t i(0); i != length; ++ i) { - fprintf(stderr, "%02hhx", output[i]); - } - fprintf(stderr, "\n"); - exit(1); - } else { - exit(0); - } - } -} - -/* - * Waits for pid to terminate and checks it terminates successfully (with 0). - */ -bool -process_ok(pid_t process) { - int status; - // Make sure it does terminate when the output is shorter than expected - /* - * FIXME: if the timeout is reached, this kill the whole test, not just - * the waitpid call. Should have signal handler. This is no show-stopper, - * but we might have another tests to run. - */ - alarm(3); - if (waitpid(process, &status, 0) == -1) { - if (errno == EINTR) - kill(process, SIGTERM); - return false; - } - return WIFEXITED(status) && WEXITSTATUS(status) == 0; -} - /* * Helper functions to pass to run during testing. */ int -get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t addr_len) +get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t) { int result(0); - int port; + int port(0); /* * We encode the type and address family into the int and return it. * Lets ignore the port and address for now @@ -265,8 +177,11 @@ send_fd_dummy(const int destination, const int what) * the test anyway. */ char fd_data(what); - if (!write_data(destination, &fd_data, 1)) + if (!write_data(destination, &fd_data, 1)) { return -1; + } else { + return 0; + } } /* @@ -280,7 +195,7 @@ void run_test(const char *input_data, const size_t input_size, bool should_succeed = true) { // Prepare the input feeder and output checker processes - int input_fd, output_fd; + int input_fd(0), output_fd(0); pid_t input(provide_input(&input_fd, input_data, input_size)), output(check_output(&output_fd, output_data, output_size)); ASSERT_NE(-1, input) << "Couldn't start input feeder"; diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index e18c43734f..280523d278 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -1 +1 @@ -SUBDIRS = exceptions dns cc config datasrc python xfr bench +SUBDIRS = exceptions dns cc config datasrc python xfr bench util diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am new file mode 100644 index 0000000000..52114d3087 --- /dev/null +++ b/src/lib/util/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = io unittests diff --git a/src/lib/util/io/Makefile.am b/src/lib/util/io/Makefile.am new file mode 100644 index 0000000000..97e0292630 --- /dev/null +++ b/src/lib/util/io/Makefile.am @@ -0,0 +1,6 @@ +AM_CXXFLAGS = $(B10_CXXFLAGS) + +lib_LTLIBRARIES = libutil_io.la +libutil_io_la_SOURCES = fd.h fd.cc + +CLEANFILES = *.gcno *.gcda diff --git a/src/lib/util/io/fd.cc b/src/lib/util/io/fd.cc new file mode 100644 index 0000000000..c9d0564438 --- /dev/null +++ b/src/lib/util/io/fd.cc @@ -0,0 +1,68 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include "fd.h" + +#include +#include + +namespace isc { +namespace util { +namespace io { + +bool +write_data(const int fd, const char *buffer, const size_t length) { + size_t rest(length); + // Just keep writing until all is written + while (rest) { + ssize_t written(write(fd, buffer, rest)); + if (rest == -1) { + if (errno == EINTR) { // Just keep going + continue; + } else { + return false; + } + } else { // Wrote something + rest -= written; + buffer += written; + } + } + return true; +} + +ssize_t +read_data(const int fd, char *buffer, const size_t length) { + size_t rest(length), already(0); + while (rest) { // Stil something to read + ssize_t amount(read(fd, buffer, rest)); + if (rest == -1) { + if (errno == EINTR) { // Continue on interrupted call + continue; + } else { + return -1; + } + } else if (amount) { + already += amount; + rest -= amount; + buffer += amount; + } else { // EOF + return already; + } + } + return already; +} + +} +} +} diff --git a/src/lib/util/io/fd.h b/src/lib/util/io/fd.h new file mode 100644 index 0000000000..a77c8d4bbc --- /dev/null +++ b/src/lib/util/io/fd.h @@ -0,0 +1,61 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef __UTIL_IO_FD_H +#define __UTIL_IO_FD_H 1 + +#include + +/** + * @file fd.h + * @short Wrappers around common unix fd manipulation functions. + */ + +namespace isc { +namespace util { +namespace io { + +/* + * \short write() that writes everything. + * Wrapper around write(). The difference is, it never writes less data + * and looks successfull (eg. it blocks until all data are written). + * Retries on signals. + * + * \return True if sucessfull, false otherwise. The errno variable is left + * intact. + * \param fd Where to write. + * \param data The buffer to write. + * \param length How much data is there to write. + */ +bool +write_data(const int fd, const char *data, const size_t length); + +/* + * \short read() that reads everything. + * Wrapper around read(). It does not do short reads, if it returns less, + * it means there was EOF. It retries on signals. + * + * \return Number of bytes read or -1 on error. + * \param fd Where to read data from. + * \param data Where to put the data. + * \param length How many of them. + */ +ssize_t +read_data(const int fd, char *buffer, const size_t length); + +} +} +} + +#endif // __UTIL_IO_FD_H diff --git a/src/lib/util/unittests/Makefile.am b/src/lib/util/unittests/Makefile.am new file mode 100644 index 0000000000..b7026478ff --- /dev/null +++ b/src/lib/util/unittests/Makefile.am @@ -0,0 +1,7 @@ +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +AM_CXXFLAGS = $(B10_CXXFLAGS) + +lib_LTLIBRARIES = libutil_unittests.la +libutil_unittests_la_SOURCES = fork.h fork.cc + +CLEANFILES = *.gcno *.gcda diff --git a/src/lib/util/unittests/README b/src/lib/util/unittests/README new file mode 100644 index 0000000000..0ed888f87d --- /dev/null +++ b/src/lib/util/unittests/README @@ -0,0 +1,5 @@ +This directory contains some code that is useful while writing various +unittest code. It doesn't contain any code that would actually run in +bind10. + +Because this is a test code, we do not test it explicitly. diff --git a/src/lib/util/unittests/fork.cc b/src/lib/util/unittests/fork.cc new file mode 100644 index 0000000000..0c49cb60aa --- /dev/null +++ b/src/lib/util/unittests/fork.cc @@ -0,0 +1,137 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include "fork.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace isc::util::io; + +namespace { + +// Just a NOP function to ignore a signal but let it interrupt function. +void no_handler(int) { } + +}; + +namespace isc { +namespace util { +namespace unittests { + +bool +process_ok(pid_t process) { + // Create a timeout + struct sigaction ignored, original; + memset(&ignored, 0, sizeof ignored); + ignored.sa_handler = no_handler; + if (sigaction(SIGALRM, &ignored, &original)) { + return false; + } + alarm(3); + int status; + int result(waitpid(process, &status, 0) == -1); + // Cancel the alarm and return the original handler + alarm(0); + if (sigaction(SIGALRM, &original, NULL)) { + return false; + } + // Check what we found out + if (result) { + if (errno == EINTR) + kill(process, SIGTERM); + return false; + } + return WIFEXITED(status) && WEXITSTATUS(status) == 0; +} + +/* + * This creates a pipe, forks and feeds the pipe with given data. + * Used to provide the input in non-blocking/asynchronous way. + */ +pid_t +provide_input(int *read_pipe, const char *input, const size_t length) { + int pipes[2]; + if (pipe(pipes)) { + return -1; + } + *read_pipe = pipes[0]; + pid_t pid(fork()); + if (pid) { // We are in the parent + return pid; + } else { // This is in the child, just puth the data there + close(pipes[0]); + if (!write_data(pipes[1], input, length)) { + exit(1); + } else { + close(pipes[1]); + exit(0); + } + } +} + +/* + * This creates a pipe, forks and reads the pipe and compares it + * with given data. Used to check output of run in asynchronous way. + */ +pid_t +check_output(int *write_pipe, const char *output, const size_t length) { + int pipes[2]; + if (pipe(pipes)) { + return -1; + } + *write_pipe = pipes[1]; + pid_t pid(fork()); + if (pid) { // We are in parent + return pid; + } else { + close(pipes[1]); + char buffer[length + 1]; + // Try to read one byte more to see if the output ends here + size_t got_length(read_data(pipes[0], buffer, length + 1)); + bool ok(true); + if (got_length != length) { + fprintf(stderr, "Different length (expected %u, got %u)\n", + static_cast(length), + static_cast(got_length)); + ok = false; + } + if(!ok || memcmp(buffer, output, length)) { + // If the differ, print what we have + for(size_t i(0); i != got_length; ++ i) { + fprintf(stderr, "%02hhx", buffer[i]); + } + fprintf(stderr, "\n"); + for(size_t i(0); i != length; ++ i) { + fprintf(stderr, "%02hhx", output[i]); + } + fprintf(stderr, "\n"); + exit(1); + } else { + exit(0); + } + } +} + +} +} +} diff --git a/src/lib/util/unittests/fork.h b/src/lib/util/unittests/fork.h new file mode 100644 index 0000000000..c4c473b4ae --- /dev/null +++ b/src/lib/util/unittests/fork.h @@ -0,0 +1,52 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef __UTIL_UNITTESTS_FORK_H +#define __UTIL_UNITTESTS_FORK_H 1 + +#include + +/** + * @file fork.h + * @short Help functions to fork the test case process. + * Various functions to fork a process and feed some data to pipe, check + * its output and such lives here. + */ + +namespace isc { +namespace util { +namespace unittests { + +/** + * @short Checks that a process terminates correctly. + * Waits for a process to terminate (with a short timeout, this should be + * used whan the process is about tu terminate) and checks its exit code. + * + * @return True if the process terminates with 0, false otherwise. + * @param process The ID of process to wait for. + */ +bool +process_ok(pid_t process); + +pid_t +provide_input(int *read_pipe, const char *input, const size_t length); + +pid_t +check_output(int *write_pipe, const char *output, const size_t length); + +} // End of the namespace +} +} + +#endif // __UTIL_UNITTESTS_FORK_H From 88d4219ba95fa853b07c3397aeb4c2e6567e50c0 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Mon, 11 Oct 2010 14:46:50 +0000 Subject: [PATCH 14/72] Move send_fd and recv_fd to isc::util::io * They are not xfr specific and can be used by more parts of the system. * TODO: They are missing tests. git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3175 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/xfrout/tests/Makefile.am | 4 +-- src/bin/xfrout/xfrout.py.in | 4 +-- src/lib/Makefile.am | 2 +- src/lib/util/io/Makefile.am | 12 +++++++- src/lib/{xfr => util/io}/fd_share.cc | 8 +++-- src/lib/{xfr => util/io}/fd_share.h | 6 ++-- src/lib/{xfr => util/io}/fdshare_python.cc | 8 ++--- src/lib/xfr/Makefile.am | 14 ++------- src/lib/xfr/python_xfr.cc | 35 ---------------------- src/lib/xfr/xfrout_client.cc | 3 +- 10 files changed, 34 insertions(+), 62 deletions(-) rename src/lib/{xfr => util/io}/fd_share.cc (97%) rename src/lib/{xfr => util/io}/fd_share.h (94%) rename src/lib/{xfr => util/io}/fdshare_python.cc (93%) delete mode 100644 src/lib/xfr/python_xfr.cc diff --git a/src/bin/xfrout/tests/Makefile.am b/src/bin/xfrout/tests/Makefile.am index 0840b5536d..ab33ee72f5 100644 --- a/src/bin/xfrout/tests/Makefile.am +++ b/src/bin/xfrout/tests/Makefile.am @@ -5,7 +5,7 @@ EXTRA_DIST = $(PYTESTS) # required by loadable python modules. LIBRARY_PATH_PLACEHOLDER = if SET_ENV_LIBRARY_PATH -LIBRARY_PATH_PLACEHOLDER += $(ENV_LIBRARY_PATH)=$(abs_top_builddir)/src/lib/dns/.libs:$(abs_top_builddir)/src/lib/exceptions/.libs:$(abs_top_builddir)/src/lib/xfr/.libs:$$$(ENV_LIBRARY_PATH) +LIBRARY_PATH_PLACEHOLDER += $(ENV_LIBRARY_PATH)=$(abs_top_builddir)/src/lib/dns/.libs:$(abs_top_builddir)/src/lib/exceptions/.libs:$(abs_top_builddir)/src/lib/util/io/.libs:$$$(ENV_LIBRARY_PATH) endif # later will have configure option to choose this, like: coverage run --branch @@ -14,7 +14,7 @@ PYCOVERAGE = $(PYTHON) check-local: for pytest in $(PYTESTS) ; do \ echo Running test: $$pytest ; \ - env PYTHONPATH=$(abs_top_builddir)/src/bin/xfrout:$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python:$(abs_top_builddir)/src/lib/dns/python/.libs:$(abs_top_builddir)/src/lib/xfr/.libs \ + env PYTHONPATH=$(abs_top_builddir)/src/bin/xfrout:$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python:$(abs_top_builddir)/src/lib/dns/python/.libs:$(abs_top_builddir)/src/lib/util/io/.libs \ $(LIBRARY_PATH_PLACEHOLDER) \ $(PYCOVERAGE) $(abs_srcdir)/$$pytest || exit ; \ done diff --git a/src/bin/xfrout/xfrout.py.in b/src/bin/xfrout/xfrout.py.in index 2354a52793..fe60cd19d2 100644 --- a/src/bin/xfrout/xfrout.py.in +++ b/src/bin/xfrout/xfrout.py.in @@ -35,12 +35,12 @@ import select import errno from optparse import OptionParser, OptionValueError try: - from libxfr_python import * + from libutil_io_python import * from pydnspp import * except ImportError as e: # C++ loadable module may not be installed; even so the xfrout process # must keep running, so we warn about it and move forward. - sys.stderr.write('[b10-xfrout] failed to import DNS or XFR module: %s\n' % str(e)) + sys.stderr.write('[b10-xfrout] failed to import DNS or isc.util.io module: %s\n' % str(e)) isc.utils.process.rename() diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 280523d278..6b951948f8 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -1 +1 @@ -SUBDIRS = exceptions dns cc config datasrc python xfr bench util +SUBDIRS = exceptions dns cc config datasrc bench util xfr python diff --git a/src/lib/util/io/Makefile.am b/src/lib/util/io/Makefile.am index 97e0292630..b2653d8b34 100644 --- a/src/lib/util/io/Makefile.am +++ b/src/lib/util/io/Makefile.am @@ -1,6 +1,16 @@ AM_CXXFLAGS = $(B10_CXXFLAGS) lib_LTLIBRARIES = libutil_io.la -libutil_io_la_SOURCES = fd.h fd.cc +libutil_io_la_SOURCES = fd.h fd.cc fd_share.h fd_share.cc +libutil_io_la_CXXFLAGS = $(AM_CXXFLAGS) -fno-strict-aliasing CLEANFILES = *.gcno *.gcda + +pyexec_LTLIBRARIES = libutil_io_python.la +# Python prefers .so, while some OSes (specifically MacOS) use a different +# suffix for dynamic objects. -module is necessary to work this around. +libutil_io_python_la_LDFLAGS = -module +libutil_io_python_la_SOURCES = fdshare_python.cc +libutil_io_python_la_LIBADD = libutil_io.la +libutil_io_python_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES) +libutil_io_python_la_CXXFLAGS = $(AM_CXXFLAGS) diff --git a/src/lib/xfr/fd_share.cc b/src/lib/util/io/fd_share.cc similarity index 97% rename from src/lib/xfr/fd_share.cc rename to src/lib/util/io/fd_share.cc index bc7824ba63..0d0dd4d9c2 100644 --- a/src/lib/xfr/fd_share.cc +++ b/src/lib/util/io/fd_share.cc @@ -21,10 +21,11 @@ #include #include #include // for malloc and free -#include +#include "fd_share.h" namespace isc { -namespace xfr { +namespace util { +namespace io { namespace { // Not all OSes support advanced CMSG macros: CMSG_LEN and CMSG_SPACE. @@ -135,5 +136,6 @@ send_fd(const int sock, const int fd) { return (ret >= 0 ? 0 : -1); } -} // End for namespace xfr +} // End for namespace io +} // End for namespace util } // End for namespace isc diff --git a/src/lib/xfr/fd_share.h b/src/lib/util/io/fd_share.h similarity index 94% rename from src/lib/xfr/fd_share.h rename to src/lib/util/io/fd_share.h index 8eece8969c..dcaae4541a 100644 --- a/src/lib/xfr/fd_share.h +++ b/src/lib/util/io/fd_share.h @@ -18,7 +18,8 @@ #define FD_SHARE_H_ namespace isc { -namespace xfr { +namespace util { +namespace io { // Receive socket descriptor on unix domain socket 'sock'. // Returned value is the socket descriptor received. @@ -30,7 +31,8 @@ int recv_fd(const int sock); // Errors are indicated by a return value of -1. int send_fd(const int sock, const int fd); -} // End for namespace xfr +} // End for namespace io +} // End for namespace util } // End for namespace isc #endif diff --git a/src/lib/xfr/fdshare_python.cc b/src/lib/util/io/fdshare_python.cc similarity index 93% rename from src/lib/xfr/fdshare_python.cc rename to src/lib/util/io/fdshare_python.cc index b28c12f535..a5b538276f 100644 --- a/src/lib/xfr/fdshare_python.cc +++ b/src/lib/util/io/fdshare_python.cc @@ -20,7 +20,7 @@ #include -#include +#include "fd_share.h" static PyObject* fdshare_recv_fd(PyObject *self UNUSED_PARAM, PyObject *args) { @@ -28,7 +28,7 @@ fdshare_recv_fd(PyObject *self UNUSED_PARAM, PyObject *args) { if (!PyArg_ParseTuple(args, "i", &sock)) { return (NULL); } - fd = isc::xfr::recv_fd(sock); + fd = isc::util::io::recv_fd(sock); return (Py_BuildValue("i", fd)); } @@ -38,7 +38,7 @@ fdshare_send_fd(PyObject *self UNUSED_PARAM, PyObject *args) { if (!PyArg_ParseTuple(args, "ii", &sock, &fd)) { return (NULL); } - result = isc::xfr::send_fd(sock, fd); + result = isc::util::io::send_fd(sock, fd); return (Py_BuildValue("i", result)); } @@ -62,7 +62,7 @@ static PyModuleDef bind10_fdshare_python = { }; PyMODINIT_FUNC -PyInit_libxfr_python(void) { +PyInit_libutil_io_python(void) { PyObject *mod = PyModule_Create(&bind10_fdshare_python); if (mod == NULL) { return (NULL); diff --git a/src/lib/xfr/Makefile.am b/src/lib/xfr/Makefile.am index 79a2b2e839..b13368c642 100644 --- a/src/lib/xfr/Makefile.am +++ b/src/lib/xfr/Makefile.am @@ -1,19 +1,11 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns -AM_CXXFLAGS = $(B10_CXXFLAGS) -Wno-strict-aliasing +AM_CXXFLAGS = $(B10_CXXFLAGS) AM_CXXFLAGS += -Wno-unused-parameter # see src/lib/cc/Makefile.am CLEANFILES = *.gcno *.gcda lib_LTLIBRARIES = libxfr.la -libxfr_la_SOURCES = xfrout_client.h xfrout_client.cc -libxfr_la_SOURCES += fd_share.h fd_share.cc - -pyexec_LTLIBRARIES = libxfr_python.la -# Python prefers .so, while some OSes (specifically MacOS) use a different -# suffix for dynamic objects. -module is necessary to work this around. -libxfr_python_la_LDFLAGS = -module -libxfr_python_la_SOURCES = fdshare_python.cc fd_share.cc fd_share.h -libxfr_python_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES) -libxfr_python_la_CXXFLAGS = $(AM_CXXFLAGS) +libxfr_la_SOURCES = xfrout_client.h xfrout_client.cc +libxfr_la_LIBADD = $(top_builddir)/src/lib/util/io/libutil_io.la diff --git a/src/lib/xfr/python_xfr.cc b/src/lib/xfr/python_xfr.cc deleted file mode 100644 index 4257b57b70..0000000000 --- a/src/lib/xfr/python_xfr.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -// $Id$ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace isc::xfr; -using namespace boost::python; - -BOOST_PYTHON_MODULE(bind10_xfr) -{ - def("recv_fd", &recv_fd); - def("send_fd", &send_fd); -} diff --git a/src/lib/xfr/xfrout_client.cc b/src/lib/xfr/xfrout_client.cc index 9ea201dc9b..2928dd6ce4 100644 --- a/src/lib/xfr/xfrout_client.cc +++ b/src/lib/xfr/xfrout_client.cc @@ -22,10 +22,11 @@ #include #include -#include +#include #include using namespace std; +using namespace isc::util::io; using asio::local::stream_protocol; namespace isc { From d11a387719a4ea69946801e4c865323f4b9016a3 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Mon, 11 Oct 2010 14:47:01 +0000 Subject: [PATCH 15/72] sockcreator uses the send_fd from isc::util::io git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3176 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/sockcreator.h | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h index a88a746c4f..0685800c28 100644 --- a/src/bin/sockcreator/sockcreator.h +++ b/src/bin/sockcreator/sockcreator.h @@ -23,6 +23,8 @@ #ifndef __SOCKCREATOR_H #define __SOCKCREATOR_H 1 +#include + #include #include @@ -53,16 +55,6 @@ typedef int (*get_sock_t)(const int, struct sockaddr *, const socklen_t); -/** - * Sends a payload socket file descriptor to destination file descriptor. - * This is temporary and it will be stolen somewhere in the surrounding code, - * since it is there already somewhere. - * - * TODO Actually steal it. - */ -int -send_fd(const int destination, const int payload); - /** * Type of the send_fd() function, so it can be passed as a parameter. */ @@ -100,7 +92,7 @@ int int run(const int input_fd, const int output_fd, const get_sock_t get_sock_fun = get_sock, - const send_fd_t send_fd_fun = send_fd); + const send_fd_t send_fd_fun = isc::util::io::send_fd); } // End of the namespaces } From 6f9b0595718f8f7fd5324a6252207d29c40836b2 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 12 Oct 2010 12:05:32 +0000 Subject: [PATCH 16/72] Fix Makefile.am git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3185 e5f2f494-b856-4b98-b285-d166d9295462 --- src/lib/util/unittests/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/util/unittests/Makefile.am b/src/lib/util/unittests/Makefile.am index b7026478ff..0ea86539ff 100644 --- a/src/lib/util/unittests/Makefile.am +++ b/src/lib/util/unittests/Makefile.am @@ -3,5 +3,7 @@ AM_CXXFLAGS = $(B10_CXXFLAGS) lib_LTLIBRARIES = libutil_unittests.la libutil_unittests_la_SOURCES = fork.h fork.cc +libutil_unittests_la_LIBADD = \ + $(top_builddir)/src/lib/util/io/libutil_io.la CLEANFILES = *.gcno *.gcda From e88330e1dbfed90776b634513372f71caa96ac5f Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 12 Oct 2010 12:05:42 +0000 Subject: [PATCH 17/72] Use void * as memory buffers, not char * For one, many builtin functions do this (memcpy, read, etc). And, it would be more correct to use unsigned char * (because of aliasing rules), but that makes C++ unhappy when passing string literals there. Got rid of -fno-strict-aliasing in sockcreator tests. git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3186 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/tests/Makefile.am | 5 ---- .../sockcreator/tests/sockcreator_tests.cc | 30 ++++++++++--------- src/lib/util/io/fd.cc | 6 ++-- src/lib/util/io/fd.h | 4 +-- src/lib/util/unittests/fork.cc | 12 +++++--- src/lib/util/unittests/fork.h | 4 +-- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/bin/sockcreator/tests/Makefile.am b/src/bin/sockcreator/tests/Makefile.am index 41d7e835c5..2e1307ad20 100644 --- a/src/bin/sockcreator/tests/Makefile.am +++ b/src/bin/sockcreator/tests/Makefile.am @@ -1,11 +1,6 @@ CLEANFILES = *.gcno *.gcda AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib -# This is here because of juggling with sockaddr pointer. -# It is somehow required by the BSD socket interface, but it -# breaks C++ strict aliasing rules, so we need to ask the compiler -# not to use them. -AM_CPPFLAGS += -fno-strict-aliasing AM_CXXFLAGS = $(B10_CXXFLAGS) if USE_STATIC_LINK diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index bdedf19c1d..09c16e1093 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -39,8 +39,8 @@ namespace { * This is a macro so ASSERT_* does abort the TEST, not just the * function inside. */ -#define TEST_ANY_CREATE(SOCK_TYPE, ADDR_TYPE, ADDR_FAMILY, ADDR_SET, \ - CHECK_SOCK) \ +#define TEST_ANY_CREATE(SOCK_TYPE, ADDR_TYPE, ADDR_FAMILY, FAMILY_FIELD, \ + ADDR_SET, CHECK_SOCK) \ do { \ /* * This should create an address that binds on all interfaces @@ -49,9 +49,9 @@ namespace { struct ADDR_TYPE addr; \ memset(&addr, 0, sizeof addr); \ ADDR_SET(addr); \ + addr.FAMILY_FIELD = ADDR_FAMILY; \ struct sockaddr *addr_ptr = static_cast( \ static_cast(&addr)); \ - addr_ptr->sa_family = ADDR_FAMILY; \ \ int socket = get_sock(SOCK_TYPE, addr_ptr, sizeof addr); \ /* Provide even nice error message. */ \ @@ -89,23 +89,25 @@ namespace { * Several tests to ensure we can create the sockets. */ TEST(get_sock, udp4_create) { - TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in, AF_INET, INADDR_SET, UDP_CHECK); -} - -TEST(get_sock, tcp4_create) { - TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in, AF_INET, INADDR_SET, TCP_CHECK); -} - -TEST(get_sock, udp6_create) { - TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in6, AF_INET6, IN6ADDR_SET, + TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in, AF_INET, sin_family, INADDR_SET, UDP_CHECK); } -TEST(get_sock, tcp6_create) { - TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in6, AF_INET6, IN6ADDR_SET, +TEST(get_sock, tcp4_create) { + TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in, AF_INET, sin_family, INADDR_SET, TCP_CHECK); } +TEST(get_sock, udp6_create) { + TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in6, AF_INET6, sin6_family, + IN6ADDR_SET, UDP_CHECK); +} + +TEST(get_sock, tcp6_create) { + TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in6, AF_INET6, sin6_family, + IN6ADDR_SET, TCP_CHECK); +} + /* * Try to ask the get_sock function some nonsense and test if it * is able to report error. diff --git a/src/lib/util/io/fd.cc b/src/lib/util/io/fd.cc index c9d0564438..7ae8619020 100644 --- a/src/lib/util/io/fd.cc +++ b/src/lib/util/io/fd.cc @@ -22,7 +22,8 @@ namespace util { namespace io { bool -write_data(const int fd, const char *buffer, const size_t length) { +write_data(const int fd, const void *buffer_v, const size_t length) { + const unsigned char *buffer(static_cast(buffer_v)); size_t rest(length); // Just keep writing until all is written while (rest) { @@ -42,7 +43,8 @@ write_data(const int fd, const char *buffer, const size_t length) { } ssize_t -read_data(const int fd, char *buffer, const size_t length) { +read_data(const int fd, void *buffer_v, const size_t length) { + unsigned char *buffer(static_cast(buffer_v)); size_t rest(length), already(0); while (rest) { // Stil something to read ssize_t amount(read(fd, buffer, rest)); diff --git a/src/lib/util/io/fd.h b/src/lib/util/io/fd.h index a77c8d4bbc..a19ca26799 100644 --- a/src/lib/util/io/fd.h +++ b/src/lib/util/io/fd.h @@ -39,7 +39,7 @@ namespace io { * \param length How much data is there to write. */ bool -write_data(const int fd, const char *data, const size_t length); +write_data(const int fd, const void *data, const size_t length); /* * \short read() that reads everything. @@ -52,7 +52,7 @@ write_data(const int fd, const char *data, const size_t length); * \param length How many of them. */ ssize_t -read_data(const int fd, char *buffer, const size_t length); +read_data(const int fd, void *buffer, const size_t length); } } diff --git a/src/lib/util/unittests/fork.cc b/src/lib/util/unittests/fork.cc index 0c49cb60aa..2b665a231b 100644 --- a/src/lib/util/unittests/fork.cc +++ b/src/lib/util/unittests/fork.cc @@ -69,7 +69,8 @@ process_ok(pid_t process) { * Used to provide the input in non-blocking/asynchronous way. */ pid_t -provide_input(int *read_pipe, const char *input, const size_t length) { +provide_input(int *read_pipe, const void *input, const size_t length) +{ int pipes[2]; if (pipe(pipes)) { return -1; @@ -94,7 +95,8 @@ provide_input(int *read_pipe, const char *input, const size_t length) { * with given data. Used to check output of run in asynchronous way. */ pid_t -check_output(int *write_pipe, const char *output, const size_t length) { +check_output(int *write_pipe, const void *output, const size_t length) +{ int pipes[2]; if (pipe(pipes)) { return -1; @@ -105,7 +107,7 @@ check_output(int *write_pipe, const char *output, const size_t length) { return pid; } else { close(pipes[1]); - char buffer[length + 1]; + unsigned char buffer[length + 1]; // Try to read one byte more to see if the output ends here size_t got_length(read_data(pipes[0], buffer, length + 1)); bool ok(true); @@ -116,13 +118,15 @@ check_output(int *write_pipe, const char *output, const size_t length) { ok = false; } if(!ok || memcmp(buffer, output, length)) { + const unsigned char *output_c(static_cast( + output)); // If the differ, print what we have for(size_t i(0); i != got_length; ++ i) { fprintf(stderr, "%02hhx", buffer[i]); } fprintf(stderr, "\n"); for(size_t i(0); i != length; ++ i) { - fprintf(stderr, "%02hhx", output[i]); + fprintf(stderr, "%02hhx", output_c[i]); } fprintf(stderr, "\n"); exit(1); diff --git a/src/lib/util/unittests/fork.h b/src/lib/util/unittests/fork.h index c4c473b4ae..55cff68000 100644 --- a/src/lib/util/unittests/fork.h +++ b/src/lib/util/unittests/fork.h @@ -40,10 +40,10 @@ bool process_ok(pid_t process); pid_t -provide_input(int *read_pipe, const char *input, const size_t length); +provide_input(int *read_pipe, const void *input, const size_t length); pid_t -check_output(int *write_pipe, const char *output, const size_t length); +check_output(int *write_pipe, const void *output, const size_t length); } // End of the namespace } From 344410fec60755f6b5cb2348ec9e7b67068f31ae Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 12 Oct 2010 12:05:51 +0000 Subject: [PATCH 18/72] Tests for isc::util::io git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3187 e5f2f494-b856-4b98-b285-d166d9295462 --- configure.ac | 1 + src/lib/util/Makefile.am | 4 +- src/lib/util/io/tests/Makefile.am | 25 +++++++++ src/lib/util/io/tests/fd_share_tests.cc | 74 +++++++++++++++++++++++++ src/lib/util/io/tests/fd_tests.cc | 66 ++++++++++++++++++++++ src/lib/util/io/tests/run_unittests.cc | 22 ++++++++ 6 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 src/lib/util/io/tests/Makefile.am create mode 100644 src/lib/util/io/tests/fd_share_tests.cc create mode 100644 src/lib/util/io/tests/fd_tests.cc create mode 100644 src/lib/util/io/tests/run_unittests.cc diff --git a/configure.ac b/configure.ac index f34f2fb1da..db67a7bd20 100644 --- a/configure.ac +++ b/configure.ac @@ -510,6 +510,7 @@ AC_CONFIG_FILES([Makefile src/lib/xfr/Makefile src/lib/util/Makefile src/lib/util/io/Makefile + src/lib/util/io/tests/Makefile src/lib/util/unittests/Makefile ]) AC_OUTPUT([src/bin/cfgmgr/b10-cfgmgr.py diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am index 52114d3087..3e74708405 100644 --- a/src/lib/util/Makefile.am +++ b/src/lib/util/Makefile.am @@ -1 +1,3 @@ -SUBDIRS = io unittests +SUBDIRS = io unittests io/tests +# The io/tests is hack, because otherwise we can not order these directories +# properly. Unittests use io and io/tests use unittest. diff --git a/src/lib/util/io/tests/Makefile.am b/src/lib/util/io/tests/Makefile.am new file mode 100644 index 0000000000..56d50cf53f --- /dev/null +++ b/src/lib/util/io/tests/Makefile.am @@ -0,0 +1,25 @@ +CLEANFILES = *.gcno *.gcda + +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +AM_CXXFLAGS = $(B10_CXXFLAGS) + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +TESTS = +if HAVE_GTEST +TESTS += run_unittests +run_unittests_SOURCES = run_unittests.cc +run_unittests_SOURCES += fd_tests.cc +run_unittests_SOURCES += fd_share_tests.cc + +run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) +run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) +run_unittests_LDADD = $(GTEST_LDADD) +run_unittests_LDADD += $(top_builddir)/src/lib/util/io/libutil_io.la +run_unittests_LDADD += \ + $(top_builddir)/src/lib/util/unittests/libutil_unittests.la +endif + +noinst_PROGRAMS = $(TESTS) diff --git a/src/lib/util/io/tests/fd_share_tests.cc b/src/lib/util/io/tests/fd_share_tests.cc new file mode 100644 index 0000000000..88a00156aa --- /dev/null +++ b/src/lib/util/io/tests/fd_share_tests.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include "../fd.h" +#include "../fd_share.h" + +#include + +#include +#include +#include +#include +#include + +using namespace isc::util::io; +using namespace isc::util::unittests; + +namespace { + +// We test that we can transfer a pipe over other pipe +TEST(FDShare, transfer) { + // Get a pipe and fork + int pipes[2]; + ASSERT_NE(-1, socketpair(AF_UNIX, SOCK_STREAM, 0, pipes)); + pid_t sender(fork()); + ASSERT_NE(-1, sender); + if(sender) { // We are in parent + // Close the other side of pipe, we want only writible one + EXPECT_NE(-1, close(pipes[0])); + // Get a process to check data + int fd(0); + pid_t checker(check_output(&fd, "data", 4)); + ASSERT_NE(-1, checker); + // Now, send the file descriptor, close it and close the pipe + EXPECT_NE(-1, send_fd(pipes[1], fd)); + EXPECT_NE(-1, close(pipes[1])); + EXPECT_NE(-1, close(fd)); + // Check both subprocesses ended well + EXPECT_TRUE(process_ok(sender)); + EXPECT_TRUE(process_ok(checker)); + } else { // We are in child. We do not use ASSERT here + // Close the write end, we only read + if(close(pipes[1])) { + exit(1); + } + // Get the file descriptor + int fd(recv_fd(pipes[0])); + if(fd == -1) { + exit(1); + } + // This pipe is not needed + if(close(pipes[0])) { + exit(1); + } + // Send "data" trough the received fd, close it and be done + if(!write_data(fd, "data", 4) || close(fd) == -1) { + exit(1); + } + exit(0); + } +} + +} diff --git a/src/lib/util/io/tests/fd_tests.cc b/src/lib/util/io/tests/fd_tests.cc new file mode 100644 index 0000000000..1953077537 --- /dev/null +++ b/src/lib/util/io/tests/fd_tests.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include "../fd.h" + +#include + +#include + +using namespace isc::util::io; +using namespace isc::util::unittests; + +namespace { + +// Make sure the test is large enough and does not fit into one +// read or write request +const size_t TEST_DATA_SIZE = 8 * 1024 * 1024; + +class FDTest : public ::testing::Test { + public: + unsigned char *data, *buffer; + FDTest() : + // We do not care what is inside, we just need it to be the same + data(new unsigned char[TEST_DATA_SIZE]), + buffer(NULL) + { } + ~ FDTest() { + delete[] data; + delete[] buffer; + } +}; + +// Test we read what was sent +TEST_F(FDTest, read) { + int read_pipe(0); + buffer = new unsigned char[TEST_DATA_SIZE]; + pid_t feeder(provide_input(&read_pipe, data, TEST_DATA_SIZE)); + ASSERT_GE(feeder, 0); + ssize_t received(read_data(read_pipe, buffer, TEST_DATA_SIZE)); + EXPECT_TRUE(process_ok(feeder)); + EXPECT_EQ(TEST_DATA_SIZE, received); + EXPECT_EQ(0, memcmp(data, buffer, received)); +} + +// Test we write the correct thing +TEST_F(FDTest, write) { + int write_pipe(0); + pid_t checker(check_output(&write_pipe, data, TEST_DATA_SIZE)); + ASSERT_GE(checker, 0); + EXPECT_TRUE(write_data(write_pipe, data, TEST_DATA_SIZE)); + EXPECT_EQ(0, close(write_pipe)); + EXPECT_TRUE(process_ok(checker)); +} + +} diff --git a/src/lib/util/io/tests/run_unittests.cc b/src/lib/util/io/tests/run_unittests.cc new file mode 100644 index 0000000000..74c27b2ba5 --- /dev/null +++ b/src/lib/util/io/tests/run_unittests.cc @@ -0,0 +1,22 @@ +// Copyright (C) 2010 CZ NIC +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include + +int +main(int argc, char *argv[]) { + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} From c7a0fffa73e28d0d28b3706a9bc6b6e1ed9d2a7b Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 12 Oct 2010 12:06:01 +0000 Subject: [PATCH 19/72] Note a restriction discovered by test git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3188 e5f2f494-b856-4b98-b285-d166d9295462 --- src/bin/sockcreator/README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bin/sockcreator/README b/src/bin/sockcreator/README index d32cff3966..d3abc9e4c8 100644 --- a/src/bin/sockcreator/README +++ b/src/bin/sockcreator/README @@ -20,6 +20,9 @@ binary protocol from stdin and does what the commands ask. Command is a single byte (usually from the printable range, so it is easier to debug and guess what it does), followed by parameters. +Note that as send_fd and recv_fd works only with unix domain socket, it's stdio +must be a socket, not pipe. + * 'T': It has no parameters. It asks the socket creator to terminate. * 'S' 'U|T' '4|6' port address: Asks it to create a port. First parameter From 4434d7bef7a127ad8fb7e9dc6a43c9bd9e6601d1 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Tue, 12 Oct 2010 12:06:14 +0000 Subject: [PATCH 20/72] Doxyfication of fd_share git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-sockcreator@3189 e5f2f494-b856-4b98-b285-d166d9295462 --- src/lib/util/io/fd_share.h | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/lib/util/io/fd_share.h b/src/lib/util/io/fd_share.h index dcaae4541a..1e4d1c7a7f 100644 --- a/src/lib/util/io/fd_share.h +++ b/src/lib/util/io/fd_share.h @@ -17,18 +17,37 @@ #ifndef FD_SHARE_H_ #define FD_SHARE_H_ +/** + * \file fd_share.h + * \short Support to transfer file descriptors between processes. + */ + namespace isc { namespace util { namespace io { -// Receive socket descriptor on unix domain socket 'sock'. -// Returned value is the socket descriptor received. -// Errors are indicated by a return value of -1. +/** + * \short Receives a file descriptor. + * This receives a file descriptor sent over an unix domain socket. This + * is the counterpart of send_fd(). + * + * @return -1 on error, the socket descriptor on success. + * @param sock The unix domain socket to read from. Tested and it does + * not work with a pipe. + */ int recv_fd(const int sock); -// Send socket descriptor "fd" to server over unix domain socket 'sock', -// the connection from socket 'sock' to unix domain server should be established first. -// Errors are indicated by a return value of -1. +/** + * \short Sends a file descriptor. + * This sends a file descriptor over an unix domain socket. This is the + * counterpart of recv_fd(). + * + * @return -1 on error, 0 otherwise. + * @param sock The unix domain socket to send to. Tested and it does not + * work with a pipe. + * @param fd The file descriptor to send. It should work with any valid + * file descriptor. + */ int send_fd(const int sock, const int fd); } // End for namespace io From 902005dceae646aefc03c2005e1ff2896efb909c Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Fri, 28 Jan 2011 19:53:38 +0100 Subject: [PATCH 21/72] [trac536] Test copy and assignment of OutputBuffer --- src/lib/dns/tests/buffer_unittest.cc | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/lib/dns/tests/buffer_unittest.cc b/src/lib/dns/tests/buffer_unittest.cc index 2ac9fc56a6..2d6ffcb61b 100644 --- a/src/lib/dns/tests/buffer_unittest.cc +++ b/src/lib/dns/tests/buffer_unittest.cc @@ -180,4 +180,43 @@ TEST_F(BufferTest, outputBufferClear) { obuffer.clear(); EXPECT_EQ(0, obuffer.getLength()); } + +TEST_F(BufferTest, outputBufferCopy) { + obuffer.writeData(testdata, sizeof(testdata)); + + EXPECT_NO_THROW({ + OutputBuffer copy(obuffer); + ASSERT_EQ(sizeof(testdata), copy.getLength()); + for (int i = 0; i < sizeof(testdata); i ++) { + EXPECT_EQ(testdata[i], copy[i]); + if (i + 1 < sizeof(testdata)) { + obuffer.writeUint16At(0, i); + } + EXPECT_EQ(testdata[i], copy[i]); + } + obuffer.clear(); + ASSERT_EQ(sizeof(testdata), copy.getLength()); + }); +} + +TEST_F(BufferTest, outputBufferAssign) { + OutputBuffer another(0); + another.clear(); + obuffer.writeData(testdata, sizeof(testdata)); + + EXPECT_NO_THROW({ + another = obuffer; + ASSERT_EQ(sizeof(testdata), another.getLength()); + for (int i = 0; i < sizeof(testdata); i ++) { + EXPECT_EQ(testdata[i], another[i]); + if (i + 1 < sizeof(testdata)) { + obuffer.writeUint16At(0, i); + } + EXPECT_EQ(testdata[i], another[i]); + } + obuffer.clear(); + ASSERT_EQ(sizeof(testdata), another.getLength()); + }); +} + } From 8599f0c0c2ebe7043dd65458a2302837f7c43895 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Fri, 28 Jan 2011 20:37:15 +0100 Subject: [PATCH 22/72] [trac536] Allocation and dealocation routines The rest of class is still not updated, it doesn't compile yet. --- src/lib/dns/buffer.h | 70 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h index e100876c2f..0f9514b83a 100644 --- a/src/lib/dns/buffer.h +++ b/src/lib/dns/buffer.h @@ -15,6 +15,8 @@ #ifndef __BUFFER_H #define __BUFFER_H 1 +#include +#include #include #include @@ -286,9 +288,51 @@ public: /// \brief Constructor from the initial size of the buffer. /// /// \param len The initial length of the buffer in bytes. - OutputBuffer(size_t len) { data_.reserve(len); } + OutputBuffer(size_t len) : + buffer_(NULL), + size_(0), + allocated_(len) + { + // We use malloc and free instead of C++ new[] and delete[]. + // This way we can use realloc, which may in fact do it without a copy. + buffer_ = static_cast(malloc(allocated_)); + if (buffer_ == NULL) { + throw std::bad_alloc(); + } + } + + /// \brief Copy constructor + OutputBuffer(const OutputBuffer& other) : + buffer_(NULL), + size_(other.size_), + allocated_(other.allocated_) + { + buffer_ = static_cast(malloc(allocated_)); + if (buffer_ == NULL) { + throw std::bad_alloc(); + } + memcpy(buffer_, other.buffer_, size_); + } + + ~ OutputBuffer() { + free(buffer_); + } //@} + /// \brief Assignment operator + OutputBuffer& operator =(const OutputBuffer& other) { + uint8_t* newbuff(static_cast(malloc(other.allocated_))); + if (newbuff == NULL) { + throw std::bad_alloc(); + } + free(buffer_); + buffer_ = newbuff; + size_ = other.size_; + allocated_ = other.allocated_; + memcpy(buffer_, other.buffer_, size_); + return (*this); + } + /// /// \name Getter Methods /// @@ -408,9 +452,29 @@ public: data_.insert(data_.end(), cp, cp + len); } //@} - + private: - std::vector data_; + uint8_t* buffer_; + size_t size_; + size_t allocated_; + void ensureAllocated(size_t needed_size) { + if (allocated_ < needed_size) { + // Guess some bigger size + size_t new_size = (allocated_ == 0) ? 1024 : allocated_; + while (new_size < needed_size) { + new_size *= 2; + } + // Allocate bigger space + uint8_t* new_buffer_(static_cast(realloc(buffer_, + new_size))); + if (new_buffer_ == NULL) { + // If it fails, the original block is left intact by it + throw std::bad_alloc(); + } + buffer_ = new_buffer_; + allocated_ = new_size; + } + } }; /// \brief Pointer-like types pointing to \c InputBuffer or \c OutputBuffer From 1cd8ba5e307c77ae9bc2563569366c43623bbc75 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Mon, 31 Jan 2011 10:55:56 +0100 Subject: [PATCH 23/72] [trac536] The access methods Writes, reads. --- src/lib/dns/buffer.h | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h index 0f9514b83a..7ac81f96a1 100644 --- a/src/lib/dns/buffer.h +++ b/src/lib/dns/buffer.h @@ -338,7 +338,7 @@ public: /// //@{ /// \brief Return the current capacity of the buffer. - size_t getCapacity() const { return (data_.capacity()); } + size_t getCapacity() const { return (allocated_); } /// \brief Return a pointer to the head of the data stored in the buffer. /// /// The caller can assume that the subsequent \c getLength() bytes are @@ -346,9 +346,9 @@ public: /// /// Note: The pointer returned by this method may be invalidated after a /// subsequent write operation. - const void* getData() const { return (&data_[0]); } + const void* getData() const { return (buffer_); } /// \brief Return the length of data written in the buffer. - size_t getLength() const { return (data_.size()); } + size_t getLength() const { return (size_); } /// \brief Return the value of the buffer at the specified position. /// /// \c pos must specify the valid position of the buffer; otherwise an @@ -357,10 +357,10 @@ public: /// \param pos The position in the buffer to be returned. const uint8_t& operator[](size_t pos) const { - if (pos >= data_.size()) { + if (pos >= size_) { isc_throw(InvalidBufferPosition, "read at invalid position"); } - return (data_[pos]); + return (buffer_[pos]); } //@} @@ -374,7 +374,10 @@ public: /// This method is provided as a shortcut to make a hole in the buffer /// that is to be filled in later, e.g, by \ref writeUint16At(). /// \param len The length of the gap to be inserted in bytes. - void skip(size_t len) { data_.insert(data_.end(), len, 0); } + void skip(size_t len) { + ensureAllocated(size_ + len); + size_ += len; + } /// \brief Trim the specified length of data from the end of the buffer. /// @@ -385,20 +388,23 @@ public: /// \param len The length of data that should be trimmed. void trim(size_t len) { - if (len > data_.size()) { + if (len > size_) { isc_throw(OutOfRange, "trimming too large from output buffer"); } - data_.resize(data_.size() - len); + size_ -= len; } /// \brief Clear buffer content. /// /// This method can be used to re-initialize and reuse the buffer without /// constructing a new one. - void clear() { data_.clear(); } + void clear() { size_ = 0; } /// \brief Write an unsigned 8-bit integer into the buffer. /// /// \param data The 8-bit integer to be written into the buffer. - void writeUint8(uint8_t data) { data_.push_back(data); } + void writeUint8(uint8_t data) { + ensureAllocated(size_ + 1); + buffer_[size_ ++] = data; + } /// \brief Write an unsigned 16-bit integer in host byte order into the /// buffer in network byte order. @@ -406,8 +412,9 @@ public: /// \param data The 16-bit integer to be written into the buffer. void writeUint16(uint16_t data) { - data_.push_back(static_cast((data & 0xff00U) >> 8)); - data_.push_back(static_cast(data & 0x00ffU)); + ensureAllocated(size_ + sizeof(data)); + buffer_[size_ ++] = static_cast((data & 0xff00U) >> 8); + buffer_[size_ ++] = static_cast(data & 0x00ffU); } /// \brief Write an unsigned 16-bit integer in host byte order at the /// specified position of the buffer in network byte order. @@ -422,12 +429,12 @@ public: /// \param pos The beginning position in the buffer to write the data. void writeUint16At(uint16_t data, size_t pos) { - if (pos + sizeof(data) > data_.size()) { + if (pos + sizeof(data) > size_) { isc_throw(InvalidBufferPosition, "write at invalid position"); } - data_[pos] = static_cast((data & 0xff00U) >> 8); - data_[pos + 1] = static_cast(data & 0x00ffU); + buffer_[pos] = static_cast((data & 0xff00U) >> 8); + buffer_[pos + 1] = static_cast(data & 0x00ffU); } /// \brief Write an unsigned 32-bit integer in host byte order /// into the buffer in network byte order. @@ -435,10 +442,11 @@ public: /// \param data The 32-bit integer to be written into the buffer. void writeUint32(uint32_t data) { - data_.push_back(static_cast((data & 0xff000000) >> 24)); - data_.push_back(static_cast((data & 0x00ff0000) >> 16)); - data_.push_back(static_cast((data & 0x0000ff00) >> 8)); - data_.push_back(static_cast(data & 0x000000ff)); + ensureAllocated(size_ + sizeof(data)); + buffer_[size_ ++] = static_cast((data & 0xff000000) >> 24); + buffer_[size_ ++] = static_cast((data & 0x00ff0000) >> 16); + buffer_[size_ ++] = static_cast((data & 0x0000ff00) >> 8); + buffer_[size_ ++] = static_cast(data & 0x000000ff); } /// \brief Copy an arbitrary length of data into the buffer. /// @@ -448,8 +456,9 @@ public: /// \param len The length of the data in bytes. void writeData(const void *data, size_t len) { - const uint8_t* cp = static_cast(data); - data_.insert(data_.end(), cp, cp + len); + ensureAllocated(size_ + len); + memcpy(buffer_ + size_, data, len); + size_ += len; } //@} From 044c080dd3fc084f3ee7dcdcc70c8dc328bee9df Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Mon, 31 Jan 2011 11:01:51 +0100 Subject: [PATCH 24/72] [trac536] Smaller return value --- src/lib/dns/buffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h index 7ac81f96a1..b22eb5358a 100644 --- a/src/lib/dns/buffer.h +++ b/src/lib/dns/buffer.h @@ -355,7 +355,7 @@ public: /// exception class of \c InvalidBufferPosition will be thrown. /// /// \param pos The position in the buffer to be returned. - const uint8_t& operator[](size_t pos) const + uint8_t operator[](size_t pos) const { if (pos >= size_) { isc_throw(InvalidBufferPosition, "read at invalid position"); From 501462d7b9850ddca6a3d0a2c7043e3fa0923759 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Mon, 31 Jan 2011 17:25:39 +0100 Subject: [PATCH 25/72] [trac536] Some comments --- src/lib/dns/buffer.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h index b22eb5358a..39ca00bc3e 100644 --- a/src/lib/dns/buffer.h +++ b/src/lib/dns/buffer.h @@ -314,6 +314,7 @@ public: memcpy(buffer_, other.buffer_, size_); } + /// \brief Destructor ~ OutputBuffer() { free(buffer_); } @@ -463,9 +464,13 @@ public: //@} private: + // The actual data uint8_t* buffer_; + // How many bytes are used size_t size_; + // How many bytes do we have preallocated (eg. the capacity) size_t allocated_; + // Make sure at last needed_size bytes are allocated in the buffer void ensureAllocated(size_t needed_size) { if (allocated_ < needed_size) { // Guess some bigger size From 3e6c2a9c09722a48fe3e6c8a1ee35724a9397360 Mon Sep 17 00:00:00 2001 From: chenzhengzhang Date: Fri, 11 Mar 2011 13:11:03 +0800 Subject: [PATCH 26/72] [trac363] use larger size type for PyArg_ParseTuple() --- src/lib/dns/python/edns_python.cc | 10 +++-- src/lib/dns/python/message_python.cc | 40 ++++++++++++----- src/lib/dns/python/messagerenderer_python.cc | 17 +++++-- src/lib/dns/python/name_python.cc | 45 +++++++++++++++---- src/lib/dns/python/question_python.cc | 2 +- src/lib/dns/python/rcode_python.cc | 8 ++-- src/lib/dns/python/rrclass_python.cc | 11 ++--- src/lib/dns/python/rrttl_python.cc | 6 ++- src/lib/dns/python/rrtype_python.cc | 8 ++-- src/lib/dns/python/tests/edns_python_test.py | 2 +- .../dns/python/tests/message_python_test.py | 13 ++++-- .../tests/messagerenderer_python_test.py | 2 + src/lib/dns/python/tests/name_python_test.py | 13 +++++- .../dns/python/tests/question_python_test.py | 2 +- .../dns/python/tests/rrclass_python_test.py | 3 +- .../dns/python/tests/rrtype_python_test.py | 2 +- 16 files changed, 134 insertions(+), 50 deletions(-) diff --git a/src/lib/dns/python/edns_python.cc b/src/lib/dns/python/edns_python.cc index e54dba0d23..97fb13d1e2 100644 --- a/src/lib/dns/python/edns_python.cc +++ b/src/lib/dns/python/edns_python.cc @@ -297,11 +297,15 @@ EDNS_getUDPSize(const s_EDNS* const self) { PyObject* EDNS_setUDPSize(s_EDNS* self, PyObject* args) { - unsigned int size; - if (!PyArg_ParseTuple(args, "I", &size)) { + long size; + if (!PyArg_ParseTuple(args, "l", &size)) { + PyErr_Clear(); + PyErr_SetString(PyExc_TypeError, + "No valid type in set_udp_size argument"); return (NULL); } - if (size > 65535) { + if (size < 0 || size > 0xffff) { + PyErr_Clear(); PyErr_SetString(PyExc_OverflowError, "UDP size is not an unsigned 16-bit integer"); return (NULL); diff --git a/src/lib/dns/python/message_python.cc b/src/lib/dns/python/message_python.cc index e19547e17b..0bfc9e4d55 100644 --- a/src/lib/dns/python/message_python.cc +++ b/src/lib/dns/python/message_python.cc @@ -226,9 +226,9 @@ static PyTypeObject message_type = { static int Message_init(s_Message* self, PyObject* args) { - unsigned int i; + long i; - if (PyArg_ParseTuple(args, "I", &i)) { + if (PyArg_ParseTuple(args, "l", &i)) { PyErr_Clear(); if (i == Message::PARSE) { self->message = new Message(Message::PARSE); @@ -274,17 +274,18 @@ Message_getHeaderFlag(s_Message* self, PyObject* args) { static PyObject* Message_setHeaderFlag(s_Message* self, PyObject* args) { - int messageflag; + long messageflag; PyObject *on = Py_True; - if (!PyArg_ParseTuple(args, "i|O!", &messageflag, &PyBool_Type, &on)) { + if (!PyArg_ParseTuple(args, "l|O!", &messageflag, &PyBool_Type, &on)) { PyErr_Clear(); PyErr_SetString(PyExc_TypeError, "no valid type in set_header_flag argument"); return (NULL); } - if (messageflag < 0) { - PyErr_SetString(PyExc_TypeError, "invalid Message header flag"); + if (messageflag < 0 || messageflag > 0xffff) { + PyErr_Clear(); + PyErr_SetString(PyExc_OverflowError, "Message header flag out of range"); return (NULL); } @@ -310,10 +311,20 @@ Message_getQid(s_Message* self) { static PyObject* Message_setQid(s_Message* self, PyObject* args) { - uint16_t id; - if (!PyArg_ParseTuple(args, "H", &id)) { + int id; + if (!PyArg_ParseTuple(args, "i", &id)) { + PyErr_Clear(); + PyErr_SetString(PyExc_TypeError, + "no valid type in set_qid argument"); return (NULL); } + if (id < 0 || id > 0xffff) { + PyErr_Clear(); + PyErr_SetString(PyExc_OverflowError, + "Message id out of range"); + return (NULL); + } + try { self->message->setQid(id); Py_RETURN_NONE; @@ -565,12 +576,17 @@ Message_addQuestion(s_Message* self, PyObject* args) { static PyObject* Message_addRRset(s_Message* self, PyObject* args) { PyObject *sign = Py_False; - unsigned int section; + int section; s_RRset* rrset; - if (!PyArg_ParseTuple(args, "IO!|O!", §ion, &rrset_type, &rrset, + if (!PyArg_ParseTuple(args, "iO!|O!", §ion, &rrset_type, &rrset, &PyBool_Type, &sign)) { return (NULL); } + if (section < 0 || section > 3) { + PyErr_Clear(); + PyErr_SetString(PyExc_OverflowError, "Message section number out of range"); + return (NULL); + } try { self->message->addRRset(static_cast(section), @@ -591,8 +607,8 @@ Message_addRRset(s_Message* self, PyObject* args) { static PyObject* Message_clear(s_Message* self, PyObject* args) { - unsigned int i; - if (PyArg_ParseTuple(args, "I", &i)) { + long i; + if (PyArg_ParseTuple(args, "l", &i)) { PyErr_Clear(); if (i == Message::PARSE) { self->message->clear(Message::PARSE); diff --git a/src/lib/dns/python/messagerenderer_python.cc b/src/lib/dns/python/messagerenderer_python.cc index a00d8d4597..8e0421d155 100644 --- a/src/lib/dns/python/messagerenderer_python.cc +++ b/src/lib/dns/python/messagerenderer_python.cc @@ -178,8 +178,17 @@ static PyObject* MessageRenderer_setLengthLimit(s_MessageRenderer* self, PyObject* args) { - unsigned int lengthlimit; - if (!PyArg_ParseTuple(args, "I", &lengthlimit)) { + long lengthlimit; + if (!PyArg_ParseTuple(args, "l", &lengthlimit)) { + PyErr_Clear(); + PyErr_SetString(PyExc_TypeError, + "No valid type in set_length_limit argument"); + return (NULL); + } + if (lengthlimit < 0 || lengthlimit > 0xffff) { + PyErr_Clear(); + PyErr_SetString(PyExc_OverflowError, + "MessageRenderer length limit out of range"); return (NULL); } self->messagerenderer->setLengthLimit(lengthlimit); @@ -190,8 +199,8 @@ static PyObject* MessageRenderer_setCompressMode(s_MessageRenderer* self, PyObject* args) { - unsigned int mode; - if (!PyArg_ParseTuple(args, "I", &mode)) { + long mode; + if (!PyArg_ParseTuple(args, "l", &mode)) { return (NULL); } diff --git a/src/lib/dns/python/name_python.cc b/src/lib/dns/python/name_python.cc index 3d7a1960b9..e0793131c0 100644 --- a/src/lib/dns/python/name_python.cc +++ b/src/lib/dns/python/name_python.cc @@ -321,14 +321,20 @@ Name_init(s_Name* self, PyObject* args) { PyObject* bytes_obj; const char* bytes; Py_ssize_t len; - unsigned int position = 0; + long position = 0; // It was not a string (see comment above), so try bytes, and // create with buffer object - if (PyArg_ParseTuple(args, "O|IO!", &bytes_obj, &position, + if (PyArg_ParseTuple(args, "O|lO!", &bytes_obj, &position, &PyBool_Type, &downcase) && PyObject_AsCharBuffer(bytes_obj, &bytes, &len) != -1) { try { + if (position < 0 || position > 0xffff) { + PyErr_Clear(); + PyErr_SetString(PyExc_OverflowError, + "Name index out of range"); + return (-1); + } InputBuffer buffer(bytes, len); buffer.setPosition(position); @@ -363,10 +369,17 @@ Name_destroy(s_Name* self) { static PyObject* Name_at(s_Name* self, PyObject* args) { - unsigned int pos; - if (!PyArg_ParseTuple(args, "I", &pos)) { + long pos; + if (!PyArg_ParseTuple(args, "l", &pos)) { return (NULL); } + if (pos < 0 || pos > 0xffff) { + PyErr_Clear(); + PyErr_SetString(PyExc_OverflowError, + "name index out of range"); + return (NULL); + } + try { return (Py_BuildValue("I", self->name->at(pos))); } catch (const isc::OutOfRange&) { @@ -459,10 +472,16 @@ Name_equals(s_Name* self, PyObject* args) { static PyObject* Name_split(s_Name* self, PyObject* args) { - unsigned int first, n; + long first, n; s_Name* ret = NULL; - - if (PyArg_ParseTuple(args, "II", &first, &n)) { + + if (PyArg_ParseTuple(args, "ll", &first, &n)) { + if (first < 0 || first > 0xffff || n < 0 || n > 0xffff) { + PyErr_Clear(); + PyErr_SetString(PyExc_OverflowError, + "name index out of range"); + return (NULL); + } ret = PyObject_New(s_Name, &name_type); if (ret != NULL) { ret->name = NULL; @@ -477,7 +496,13 @@ Name_split(s_Name* self, PyObject* args) { return (NULL); } } - } else if (PyArg_ParseTuple(args, "I", &n)) { + } else if (PyArg_ParseTuple(args, "l", &n)) { + if (n < 0 || n > 0xffff) { + PyErr_Clear(); + PyErr_SetString(PyExc_OverflowError, + "name index out of range"); + return (NULL); + } ret = PyObject_New(s_Name, &name_type); if (ret != NULL) { ret->name = NULL; @@ -493,6 +518,10 @@ Name_split(s_Name* self, PyObject* args) { } } } + + PyErr_Clear(); + PyErr_SetString(PyExc_TypeError, + "No valid type in split argument"); return (ret); } #include diff --git a/src/lib/dns/python/question_python.cc b/src/lib/dns/python/question_python.cc index a0392846ee..2889350fc9 100644 --- a/src/lib/dns/python/question_python.cc +++ b/src/lib/dns/python/question_python.cc @@ -169,7 +169,7 @@ Question_init(s_Question* self, PyObject* args) { } self->question = QuestionPtr(); - + PyErr_Clear(); PyErr_SetString(PyExc_TypeError, "no valid type in constructor argument"); diff --git a/src/lib/dns/python/rcode_python.cc b/src/lib/dns/python/rcode_python.cc index fce8eefb0e..8e5674b4bb 100644 --- a/src/lib/dns/python/rcode_python.cc +++ b/src/lib/dns/python/rcode_python.cc @@ -171,16 +171,16 @@ PyTypeObject rcode_type = { int Rcode_init(s_Rcode* const self, PyObject* args) { - int code = 0; - int ext_code = 0; + long code = 0; + long ext_code = 0; - if (PyArg_ParseTuple(args, "i", &code)) { + if (PyArg_ParseTuple(args, "l", &code)) { if (code < 0 || code > 0xffff) { PyErr_SetString(PyExc_OverflowError, "Rcode out of range"); return (-1); } ext_code = -1; - } else if (PyArg_ParseTuple(args, "ii", &code, &ext_code)) { + } else if (PyArg_ParseTuple(args, "ll", &code, &ext_code)) { if (code < 0 || code > 0xff || ext_code < 0 || ext_code > 0xff) { PyErr_SetString(PyExc_OverflowError, "Rcode out of range"); return (-1); diff --git a/src/lib/dns/python/rrclass_python.cc b/src/lib/dns/python/rrclass_python.cc index 3cfed4c045..f9878c4b6e 100644 --- a/src/lib/dns/python/rrclass_python.cc +++ b/src/lib/dns/python/rrclass_python.cc @@ -152,7 +152,7 @@ static PyTypeObject rrclass_type = { static int RRClass_init(s_RRClass* self, PyObject* args) { const char* s; - unsigned int i; + long i; PyObject* bytes = NULL; // The constructor argument can be a string ("IN"), an integer (1), // or a sequence of numbers between 0 and 65535 (wire code) @@ -165,10 +165,11 @@ RRClass_init(s_RRClass* self, PyObject* args) { if (PyArg_ParseTuple(args, "s", &s)) { self->rrclass = new RRClass(s); return (0); - } else if (PyArg_ParseTuple(args, "I", &i)) { - PyErr_Clear(); - if (i > 65535) { - PyErr_SetString(po_InvalidRRClass, "RR class number too high"); + } else if (PyArg_ParseTuple(args, "l", &i)) { + if (i < 0 || i > 0xffff) { + PyErr_Clear(); + PyErr_SetString(PyExc_OverflowError, + "RR class number out of range"); return (-1); } self->rrclass = new RRClass(i); diff --git a/src/lib/dns/python/rrttl_python.cc b/src/lib/dns/python/rrttl_python.cc index e7391d0630..4d228c3166 100644 --- a/src/lib/dns/python/rrttl_python.cc +++ b/src/lib/dns/python/rrttl_python.cc @@ -158,8 +158,12 @@ RRTTL_init(s_RRTTL* self, PyObject* args) { if (PyArg_ParseTuple(args, "s", &s)) { self->rrttl = new RRTTL(s); return (0); - } else if (PyArg_ParseTuple(args, "I", &i)) { + } else if (PyArg_ParseTuple(args, "k", &i)) { PyErr_Clear(); + if (i > 0xffffffff) { + PyErr_SetString(po_InvalidRRTTL, "RR TTL number out of range"); + return (-1); + } self->rrttl = new RRTTL(i); return (0); } else if (PyArg_ParseTuple(args, "O", &bytes) && diff --git a/src/lib/dns/python/rrtype_python.cc b/src/lib/dns/python/rrtype_python.cc index 012f25119c..19af8c1314 100644 --- a/src/lib/dns/python/rrtype_python.cc +++ b/src/lib/dns/python/rrtype_python.cc @@ -182,7 +182,7 @@ static PyTypeObject rrtype_type = { static int RRType_init(s_RRType* self, PyObject* args) { const char* s; - unsigned int i; + long i; PyObject* bytes = NULL; // The constructor argument can be a string ("A"), an integer (1), // or a sequence of numbers between 0 and 65535 (wire code) @@ -195,10 +195,10 @@ RRType_init(s_RRType* self, PyObject* args) { if (PyArg_ParseTuple(args, "s", &s)) { self->rrtype = new RRType(s); return (0); - } else if (PyArg_ParseTuple(args, "I", &i)) { + } else if (PyArg_ParseTuple(args, "l", &i)) { PyErr_Clear(); - if (i > 65535) { - PyErr_SetString(po_InvalidRRType, "RR Type number too high"); + if (i < 0 || i > 0xffff) { + PyErr_SetString(PyExc_OverflowError, "RR Type number out of range"); return (-1); } self->rrtype = new RRType(i); diff --git a/src/lib/dns/python/tests/edns_python_test.py b/src/lib/dns/python/tests/edns_python_test.py index 3f03c90068..13aa2f0548 100644 --- a/src/lib/dns/python/tests/edns_python_test.py +++ b/src/lib/dns/python/tests/edns_python_test.py @@ -71,7 +71,7 @@ class EDNSTest(unittest.TestCase): # Range check. We need to do this at the binding level, so we need # explicit tests for it. - self.assertRaises(OverflowError, edns.set_udp_size, 65536) + self.assertRaises(OverflowError, edns.set_udp_size, 0x10000) self.assertRaises(OverflowError, edns.set_udp_size, -1) def test_get_version(self): diff --git a/src/lib/dns/python/tests/message_python_test.py b/src/lib/dns/python/tests/message_python_test.py index 6ef42d4cd4..b0e8d8ef91 100644 --- a/src/lib/dns/python/tests/message_python_test.py +++ b/src/lib/dns/python/tests/message_python_test.py @@ -80,8 +80,10 @@ class MessageTest(unittest.TestCase): "2001:db8::134")) self.bogus_section = Message.SECTION_ADDITIONAL + 1 + self.bogus_below_section = Message.SECTION_QUESTION - 1 def test_init(self): + self.assertRaises(TypeError, Message, -1) self.assertRaises(TypeError, Message, 3) self.assertRaises(TypeError, Message, "wrong") @@ -109,20 +111,23 @@ class MessageTest(unittest.TestCase): self.assertRaises(InvalidParameter, self.r.set_header_flag, 0) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x7000) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x0800) - self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x10000) self.assertRaises(TypeError, self.r.set_header_flag, 0x80000000) - # this would cause overflow and result in a "valid" flag self.assertRaises(TypeError, self.r.set_header_flag, Message.HEADERFLAG_AA | 0x100000000) - self.assertRaises(TypeError, self.r.set_header_flag, -1) + # this would cause overflow and result in a "valid" flag + self.assertRaises(OverflowError, self.r.set_header_flag, 0x10000) + self.assertRaises(OverflowError, self.r.set_header_flag, -1) self.assertRaises(InvalidMessageOperation, self.p.set_header_flag, Message.HEADERFLAG_AA) def test_set_qid(self): self.assertRaises(TypeError, self.r.set_qid, "wrong") + self.assertRaises(OverflowError, self.r.set_qid, -1) + self.assertRaises(OverflowError, self.r.set_qid, 0x10000) self.assertRaises(InvalidMessageOperation, self.p.set_qid, 123) + self.r.set_qid(1234) self.assertEqual(1234, self.r.get_qid()) @@ -239,6 +244,8 @@ class MessageTest(unittest.TestCase): Message.SECTION_ANSWER, self.rrset_a) self.assertRaises(OverflowError, self.r.add_rrset, self.bogus_section, self.rrset_a) + self.assertRaises(OverflowError, self.r.add_rrset, + self.bogus_below_section, self.rrset_a) def test_clear(self): self.assertEqual(None, self.r.clear(Message.PARSE)) diff --git a/src/lib/dns/python/tests/messagerenderer_python_test.py b/src/lib/dns/python/tests/messagerenderer_python_test.py index 544ad2376d..b77941fa3c 100644 --- a/src/lib/dns/python/tests/messagerenderer_python_test.py +++ b/src/lib/dns/python/tests/messagerenderer_python_test.py @@ -98,6 +98,8 @@ class MessageRendererTest(unittest.TestCase): renderer.set_length_limit(1024) self.assertEqual(1024, renderer.get_length_limit()) self.assertRaises(TypeError, renderer.set_length_limit, "wrong") + self.assertRaises(OverflowError, renderer.set_length_limit, -1) + self.assertRaises(OverflowError, renderer.set_length_limit, 0x10000) def test_messagerenderer_set_compress_mode(self): renderer = MessageRenderer() diff --git a/src/lib/dns/python/tests/name_python_test.py b/src/lib/dns/python/tests/name_python_test.py index 81060e96ce..ce417bb380 100644 --- a/src/lib/dns/python/tests/name_python_test.py +++ b/src/lib/dns/python/tests/name_python_test.py @@ -95,12 +95,16 @@ class NameTest(unittest.TestCase): b = bytearray() b += b'\x07example'*32 + b'\x03com\x00' self.assertRaises(DNSMessageFORMERR, Name, b, 0) + self.assertRaises(OverflowError, Name, b, -1) + self.assertRaises(OverflowError, Name, b, 0x10000) def test_at(self): self.assertEqual(7, self.name1.at(0)) self.assertEqual(101, self.name1.at(1)) self.assertRaises(IndexError, self.name1.at, 100) self.assertRaises(TypeError, self.name1.at, "wrong") + self.assertRaises(OverflowError, self.name1.at, -1) + self.assertRaises(OverflowError, self.name1.at, 0x10000) def test_get_length(self): self.assertEqual(13, self.name1.get_length()) @@ -153,12 +157,20 @@ class NameTest(unittest.TestCase): self.assertRaises(TypeError, self.name1.split, 1, "wrong") self.assertRaises(IndexError, self.name1.split, 123, 1) self.assertRaises(IndexError, self.name1.split, 1, 123) + # Out of range + self.assertRaises(OverflowError, self.name1.split, -1, 123) + self.assertRaises(OverflowError, self.name1.split, 0, -1) + self.assertRaises(OverflowError, self.name1.split, 1, 0x10000) + self.assertRaises(OverflowError, self.name1.split, 0x10000, 5) s = self.name1.split(1) self.assertEqual("com.", s.to_text()) s = self.name1.split(0) self.assertEqual("example.com.", s.to_text()) self.assertRaises(IndexError, self.name1.split, 123) + # Out of range + self.assertRaises(OverflowError, self.name1.split, 0x10000) + self.assertRaises(OverflowError, self.name1.split, -123) def test_reverse(self): self.assertEqual("com.example.", self.name1.reverse().to_text()) @@ -169,7 +181,6 @@ class NameTest(unittest.TestCase): self.assertEqual("example.com.example.com.", self.name1.concatenate(self.name1).to_text()) self.assertRaises(TypeError, self.name1.concatenate, "wrong") self.assertRaises(TooLongName, self.name1.concatenate, Name("example."*31)) - def test_downcase(self): self.assertEqual("EXAMPLE.com.", self.name4.to_text()) diff --git a/src/lib/dns/python/tests/question_python_test.py b/src/lib/dns/python/tests/question_python_test.py index 6c4db4b581..69e3051933 100644 --- a/src/lib/dns/python/tests/question_python_test.py +++ b/src/lib/dns/python/tests/question_python_test.py @@ -45,7 +45,7 @@ class QuestionTest(unittest.TestCase): # tests below based on cpp unit tests # also tests get_name, get_class and get_type def test_from_wire(self): - + q = question_from_wire("question_fromWire") self.assertEqual(self.example_name1, q.get_name()) diff --git a/src/lib/dns/python/tests/rrclass_python_test.py b/src/lib/dns/python/tests/rrclass_python_test.py index b5e8b5ed9d..a5a1f95502 100644 --- a/src/lib/dns/python/tests/rrclass_python_test.py +++ b/src/lib/dns/python/tests/rrclass_python_test.py @@ -32,7 +32,8 @@ class RRClassTest(unittest.TestCase): b = bytearray(1) b[0] = 123 self.assertRaises(TypeError, RRClass, b) - self.assertRaises(InvalidRRClass, RRClass, 65536) + self.assertRaises(OverflowError, RRClass, 65536) + self.assertRaises(OverflowError, RRClass, -12) self.assertEqual(self.c1, RRClass(1)) b = bytearray() self.c1.to_wire(b) diff --git a/src/lib/dns/python/tests/rrtype_python_test.py b/src/lib/dns/python/tests/rrtype_python_test.py index c35e1e7e78..cd6364fdb6 100644 --- a/src/lib/dns/python/tests/rrtype_python_test.py +++ b/src/lib/dns/python/tests/rrtype_python_test.py @@ -32,7 +32,7 @@ class TestModuleSpec(unittest.TestCase): def test_init(self): - self.assertRaises(InvalidRRType, RRType, 65537) + self.assertRaises(OverflowError, RRType, 65537) b = bytearray(b'\x00\x01') self.assertEqual(RRType("A"), RRType(b)) b = bytearray(b'\x01') From 3cc446d3ed8a1b6c899ee19faeda2c41a4b5bdb2 Mon Sep 17 00:00:00 2001 From: chenzhengzhang Date: Tue, 15 Mar 2011 19:14:27 +0800 Subject: [PATCH 27/72] [trac363] update unittest for python binding --- src/lib/dns/python/tests/message_python_test.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib/dns/python/tests/message_python_test.py b/src/lib/dns/python/tests/message_python_test.py index b0e8d8ef91..0af7110f83 100644 --- a/src/lib/dns/python/tests/message_python_test.py +++ b/src/lib/dns/python/tests/message_python_test.py @@ -111,9 +111,6 @@ class MessageTest(unittest.TestCase): self.assertRaises(InvalidParameter, self.r.set_header_flag, 0) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x7000) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x0800) - self.assertRaises(TypeError, self.r.set_header_flag, 0x80000000) - self.assertRaises(TypeError, self.r.set_header_flag, - Message.HEADERFLAG_AA | 0x100000000) # this would cause overflow and result in a "valid" flag self.assertRaises(OverflowError, self.r.set_header_flag, 0x10000) self.assertRaises(OverflowError, self.r.set_header_flag, -1) From ac453e66538072059954b8ca3e3d53bfc7c8cef3 Mon Sep 17 00:00:00 2001 From: chenzhengzhang Date: Wed, 16 Mar 2011 15:20:50 +0800 Subject: [PATCH 28/72] [trac363] minor fix according to review comments --- src/lib/dns/python/edns_python.cc | 1 - src/lib/dns/python/message_python.cc | 21 ++++++----------- src/lib/dns/python/messagerenderer_python.cc | 5 ++-- src/lib/dns/python/name_python.cc | 23 ++++++++----------- src/lib/dns/python/rcode_python.cc | 4 ++-- .../dns/python/tests/message_python_test.py | 2 +- src/lib/dns/python/tests/name_python_test.py | 3 +-- 7 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/lib/dns/python/edns_python.cc b/src/lib/dns/python/edns_python.cc index 97fb13d1e2..0622618952 100644 --- a/src/lib/dns/python/edns_python.cc +++ b/src/lib/dns/python/edns_python.cc @@ -305,7 +305,6 @@ EDNS_setUDPSize(s_EDNS* self, PyObject* args) { return (NULL); } if (size < 0 || size > 0xffff) { - PyErr_Clear(); PyErr_SetString(PyExc_OverflowError, "UDP size is not an unsigned 16-bit integer"); return (NULL); diff --git a/src/lib/dns/python/message_python.cc b/src/lib/dns/python/message_python.cc index 0bfc9e4d55..34258e9709 100644 --- a/src/lib/dns/python/message_python.cc +++ b/src/lib/dns/python/message_python.cc @@ -226,9 +226,9 @@ static PyTypeObject message_type = { static int Message_init(s_Message* self, PyObject* args) { - long i; - - if (PyArg_ParseTuple(args, "l", &i)) { + int i; + + if (PyArg_ParseTuple(args, "i", &i)) { PyErr_Clear(); if (i == Message::PARSE) { self->message = new Message(Message::PARSE); @@ -284,7 +284,6 @@ Message_setHeaderFlag(s_Message* self, PyObject* args) { return (NULL); } if (messageflag < 0 || messageflag > 0xffff) { - PyErr_Clear(); PyErr_SetString(PyExc_OverflowError, "Message header flag out of range"); return (NULL); } @@ -311,15 +310,14 @@ Message_getQid(s_Message* self) { static PyObject* Message_setQid(s_Message* self, PyObject* args) { - int id; - if (!PyArg_ParseTuple(args, "i", &id)) { + long id; + if (!PyArg_ParseTuple(args, "l", &id)) { PyErr_Clear(); PyErr_SetString(PyExc_TypeError, "no valid type in set_qid argument"); return (NULL); } if (id < 0 || id > 0xffff) { - PyErr_Clear(); PyErr_SetString(PyExc_OverflowError, "Message id out of range"); return (NULL); @@ -582,11 +580,6 @@ Message_addRRset(s_Message* self, PyObject* args) { &PyBool_Type, &sign)) { return (NULL); } - if (section < 0 || section > 3) { - PyErr_Clear(); - PyErr_SetString(PyExc_OverflowError, "Message section number out of range"); - return (NULL); - } try { self->message->addRRset(static_cast(section), @@ -607,8 +600,8 @@ Message_addRRset(s_Message* self, PyObject* args) { static PyObject* Message_clear(s_Message* self, PyObject* args) { - long i; - if (PyArg_ParseTuple(args, "l", &i)) { + int i; + if (PyArg_ParseTuple(args, "i", &i)) { PyErr_Clear(); if (i == Message::PARSE) { self->message->clear(Message::PARSE); diff --git a/src/lib/dns/python/messagerenderer_python.cc b/src/lib/dns/python/messagerenderer_python.cc index 8e0421d155..49fa3e04c4 100644 --- a/src/lib/dns/python/messagerenderer_python.cc +++ b/src/lib/dns/python/messagerenderer_python.cc @@ -186,7 +186,6 @@ MessageRenderer_setLengthLimit(s_MessageRenderer* self, return (NULL); } if (lengthlimit < 0 || lengthlimit > 0xffff) { - PyErr_Clear(); PyErr_SetString(PyExc_OverflowError, "MessageRenderer length limit out of range"); return (NULL); @@ -199,8 +198,8 @@ static PyObject* MessageRenderer_setCompressMode(s_MessageRenderer* self, PyObject* args) { - long mode; - if (!PyArg_ParseTuple(args, "l", &mode)) { + int mode; + if (!PyArg_ParseTuple(args, "i", &mode)) { return (NULL); } diff --git a/src/lib/dns/python/name_python.cc b/src/lib/dns/python/name_python.cc index e0793131c0..7be83b7ecb 100644 --- a/src/lib/dns/python/name_python.cc +++ b/src/lib/dns/python/name_python.cc @@ -329,10 +329,9 @@ Name_init(s_Name* self, PyObject* args) { &PyBool_Type, &downcase) && PyObject_AsCharBuffer(bytes_obj, &bytes, &len) != -1) { try { - if (position < 0 || position > 0xffff) { - PyErr_Clear(); - PyErr_SetString(PyExc_OverflowError, - "Name index out of range"); + if (position < 0) { + PyErr_SetString(PyExc_TypeError, + "Name index shouldn't be negative"); return (-1); } InputBuffer buffer(bytes, len); @@ -369,12 +368,11 @@ Name_destroy(s_Name* self) { static PyObject* Name_at(s_Name* self, PyObject* args) { - long pos; - if (!PyArg_ParseTuple(args, "l", &pos)) { + int pos; + if (!PyArg_ParseTuple(args, "i", &pos)) { return (NULL); } if (pos < 0 || pos > 0xffff) { - PyErr_Clear(); PyErr_SetString(PyExc_OverflowError, "name index out of range"); return (NULL); @@ -470,14 +468,13 @@ Name_equals(s_Name* self, PyObject* args) { Py_RETURN_FALSE; } -static PyObject* +static PyObject* Name_split(s_Name* self, PyObject* args) { - long first, n; + int first, n; s_Name* ret = NULL; - if (PyArg_ParseTuple(args, "ll", &first, &n)) { + if (PyArg_ParseTuple(args, "ii", &first, &n)) { if (first < 0 || first > 0xffff || n < 0 || n > 0xffff) { - PyErr_Clear(); PyErr_SetString(PyExc_OverflowError, "name index out of range"); return (NULL); @@ -496,9 +493,9 @@ Name_split(s_Name* self, PyObject* args) { return (NULL); } } - } else if (PyArg_ParseTuple(args, "l", &n)) { + } else if (PyArg_ParseTuple(args, "i", &n)) { + PyErr_Clear(); if (n < 0 || n > 0xffff) { - PyErr_Clear(); PyErr_SetString(PyExc_OverflowError, "name index out of range"); return (NULL); diff --git a/src/lib/dns/python/rcode_python.cc b/src/lib/dns/python/rcode_python.cc index 8e5674b4bb..311f4713ad 100644 --- a/src/lib/dns/python/rcode_python.cc +++ b/src/lib/dns/python/rcode_python.cc @@ -172,7 +172,7 @@ PyTypeObject rcode_type = { int Rcode_init(s_Rcode* const self, PyObject* args) { long code = 0; - long ext_code = 0; + int ext_code = 0; if (PyArg_ParseTuple(args, "l", &code)) { if (code < 0 || code > 0xffff) { @@ -180,7 +180,7 @@ Rcode_init(s_Rcode* const self, PyObject* args) { return (-1); } ext_code = -1; - } else if (PyArg_ParseTuple(args, "ll", &code, &ext_code)) { + } else if (PyArg_ParseTuple(args, "li", &code, &ext_code)) { if (code < 0 || code > 0xff || ext_code < 0 || ext_code > 0xff) { PyErr_SetString(PyExc_OverflowError, "Rcode out of range"); return (-1); diff --git a/src/lib/dns/python/tests/message_python_test.py b/src/lib/dns/python/tests/message_python_test.py index 0af7110f83..2850c8ca91 100644 --- a/src/lib/dns/python/tests/message_python_test.py +++ b/src/lib/dns/python/tests/message_python_test.py @@ -111,7 +111,7 @@ class MessageTest(unittest.TestCase): self.assertRaises(InvalidParameter, self.r.set_header_flag, 0) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x7000) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x0800) - # this would cause overflow and result in a "valid" flag + # this would cause overflow self.assertRaises(OverflowError, self.r.set_header_flag, 0x10000) self.assertRaises(OverflowError, self.r.set_header_flag, -1) diff --git a/src/lib/dns/python/tests/name_python_test.py b/src/lib/dns/python/tests/name_python_test.py index ce417bb380..e0482a96ba 100644 --- a/src/lib/dns/python/tests/name_python_test.py +++ b/src/lib/dns/python/tests/name_python_test.py @@ -95,8 +95,7 @@ class NameTest(unittest.TestCase): b = bytearray() b += b'\x07example'*32 + b'\x03com\x00' self.assertRaises(DNSMessageFORMERR, Name, b, 0) - self.assertRaises(OverflowError, Name, b, -1) - self.assertRaises(OverflowError, Name, b, 0x10000) + self.assertRaises(TypeError, Name, b, -1) def test_at(self): self.assertEqual(7, self.name1.at(0)) From 238735e15837b8dcb878bbdb627ea4b61682db60 Mon Sep 17 00:00:00 2001 From: chenzhengzhang Date: Fri, 18 Mar 2011 12:46:49 +0800 Subject: [PATCH 29/72] [trac363] update excepiton type and data type --- src/lib/dns/python/edns_python.cc | 2 +- src/lib/dns/python/message_python.cc | 4 +-- src/lib/dns/python/messagerenderer_python.cc | 2 +- src/lib/dns/python/name_python.cc | 28 +++++++++++-------- src/lib/dns/python/rcode_python.cc | 4 +-- src/lib/dns/python/rrclass_python.cc | 2 +- src/lib/dns/python/rrttl_python.cc | 8 +++--- src/lib/dns/python/rrtype_python.cc | 2 +- src/lib/dns/python/tests/edns_python_test.py | 4 +-- .../dns/python/tests/message_python_test.py | 10 +++---- .../tests/messagerenderer_python_test.py | 4 +-- src/lib/dns/python/tests/name_python_test.py | 20 ++++++------- src/lib/dns/python/tests/rcode_python_test.py | 4 ++- .../dns/python/tests/rrclass_python_test.py | 4 +-- src/lib/dns/python/tests/rrttl_python_test.py | 6 ++-- .../dns/python/tests/rrtype_python_test.py | 2 +- 16 files changed, 56 insertions(+), 50 deletions(-) diff --git a/src/lib/dns/python/edns_python.cc b/src/lib/dns/python/edns_python.cc index 0622618952..82db8d80bb 100644 --- a/src/lib/dns/python/edns_python.cc +++ b/src/lib/dns/python/edns_python.cc @@ -305,7 +305,7 @@ EDNS_setUDPSize(s_EDNS* self, PyObject* args) { return (NULL); } if (size < 0 || size > 0xffff) { - PyErr_SetString(PyExc_OverflowError, + PyErr_SetString(PyExc_ValueError, "UDP size is not an unsigned 16-bit integer"); return (NULL); } diff --git a/src/lib/dns/python/message_python.cc b/src/lib/dns/python/message_python.cc index 34258e9709..97bc28dac0 100644 --- a/src/lib/dns/python/message_python.cc +++ b/src/lib/dns/python/message_python.cc @@ -284,7 +284,7 @@ Message_setHeaderFlag(s_Message* self, PyObject* args) { return (NULL); } if (messageflag < 0 || messageflag > 0xffff) { - PyErr_SetString(PyExc_OverflowError, "Message header flag out of range"); + PyErr_SetString(PyExc_ValueError, "Message header flag out of range"); return (NULL); } @@ -318,7 +318,7 @@ Message_setQid(s_Message* self, PyObject* args) { return (NULL); } if (id < 0 || id > 0xffff) { - PyErr_SetString(PyExc_OverflowError, + PyErr_SetString(PyExc_ValueError, "Message id out of range"); return (NULL); } diff --git a/src/lib/dns/python/messagerenderer_python.cc b/src/lib/dns/python/messagerenderer_python.cc index 49fa3e04c4..73bcefc9ac 100644 --- a/src/lib/dns/python/messagerenderer_python.cc +++ b/src/lib/dns/python/messagerenderer_python.cc @@ -186,7 +186,7 @@ MessageRenderer_setLengthLimit(s_MessageRenderer* self, return (NULL); } if (lengthlimit < 0 || lengthlimit > 0xffff) { - PyErr_SetString(PyExc_OverflowError, + PyErr_SetString(PyExc_ValueError, "MessageRenderer length limit out of range"); return (NULL); } diff --git a/src/lib/dns/python/name_python.cc b/src/lib/dns/python/name_python.cc index 7be83b7ecb..1aef2a0dbb 100644 --- a/src/lib/dns/python/name_python.cc +++ b/src/lib/dns/python/name_python.cc @@ -330,7 +330,8 @@ Name_init(s_Name* self, PyObject* args) { PyObject_AsCharBuffer(bytes_obj, &bytes, &len) != -1) { try { if (position < 0) { - PyErr_SetString(PyExc_TypeError, + // Throw IndexError here since name index should be unsigned + PyErr_SetString(PyExc_IndexError, "Name index shouldn't be negative"); return (-1); } @@ -372,9 +373,10 @@ Name_at(s_Name* self, PyObject* args) { if (!PyArg_ParseTuple(args, "i", &pos)) { return (NULL); } - if (pos < 0 || pos > 0xffff) { - PyErr_SetString(PyExc_OverflowError, - "name index out of range"); + if (pos < 0) { + // Throw IndexError here since name index should be unsigned + PyErr_SetString(PyExc_IndexError, + "name index shouldn't be negative"); return (NULL); } @@ -416,10 +418,10 @@ static PyObject* Name_toWire(s_Name* self, PyObject* args) { PyObject* bytes; s_MessageRenderer* mr; - + if (PyArg_ParseTuple(args, "O", &bytes) && PySequence_Check(bytes)) { PyObject* bytes_o = bytes; - + OutputBuffer buffer(Name::MAX_WIRE); self->name->toWire(buffer); PyObject* name_bytes = PyBytes_FromStringAndSize(static_cast(buffer.getData()), buffer.getLength()); @@ -474,9 +476,10 @@ Name_split(s_Name* self, PyObject* args) { s_Name* ret = NULL; if (PyArg_ParseTuple(args, "ii", &first, &n)) { - if (first < 0 || first > 0xffff || n < 0 || n > 0xffff) { - PyErr_SetString(PyExc_OverflowError, - "name index out of range"); + if (first < 0 || n < 0) { + // Throw IndexError here since name index should be unsigned + PyErr_SetString(PyExc_IndexError, + "name index shouldn't be negative"); return (NULL); } ret = PyObject_New(s_Name, &name_type); @@ -495,9 +498,10 @@ Name_split(s_Name* self, PyObject* args) { } } else if (PyArg_ParseTuple(args, "i", &n)) { PyErr_Clear(); - if (n < 0 || n > 0xffff) { - PyErr_SetString(PyExc_OverflowError, - "name index out of range"); + if (n < 0) { + // Throw IndexError here since name index should be unsigned + PyErr_SetString(PyExc_IndexError, + "name index shouldn't be negative"); return (NULL); } ret = PyObject_New(s_Name, &name_type); diff --git a/src/lib/dns/python/rcode_python.cc b/src/lib/dns/python/rcode_python.cc index 311f4713ad..b80a93c5d1 100644 --- a/src/lib/dns/python/rcode_python.cc +++ b/src/lib/dns/python/rcode_python.cc @@ -176,13 +176,13 @@ Rcode_init(s_Rcode* const self, PyObject* args) { if (PyArg_ParseTuple(args, "l", &code)) { if (code < 0 || code > 0xffff) { - PyErr_SetString(PyExc_OverflowError, "Rcode out of range"); + PyErr_SetString(PyExc_ValueError, "Rcode out of range"); return (-1); } ext_code = -1; } else if (PyArg_ParseTuple(args, "li", &code, &ext_code)) { if (code < 0 || code > 0xff || ext_code < 0 || ext_code > 0xff) { - PyErr_SetString(PyExc_OverflowError, "Rcode out of range"); + PyErr_SetString(PyExc_ValueError, "Rcode out of range"); return (-1); } } else { diff --git a/src/lib/dns/python/rrclass_python.cc b/src/lib/dns/python/rrclass_python.cc index f9878c4b6e..ca20e68210 100644 --- a/src/lib/dns/python/rrclass_python.cc +++ b/src/lib/dns/python/rrclass_python.cc @@ -168,7 +168,7 @@ RRClass_init(s_RRClass* self, PyObject* args) { } else if (PyArg_ParseTuple(args, "l", &i)) { if (i < 0 || i > 0xffff) { PyErr_Clear(); - PyErr_SetString(PyExc_OverflowError, + PyErr_SetString(PyExc_ValueError, "RR class number out of range"); return (-1); } diff --git a/src/lib/dns/python/rrttl_python.cc b/src/lib/dns/python/rrttl_python.cc index 4d228c3166..696e1a044f 100644 --- a/src/lib/dns/python/rrttl_python.cc +++ b/src/lib/dns/python/rrttl_python.cc @@ -145,7 +145,7 @@ static PyTypeObject rrttl_type = { static int RRTTL_init(s_RRTTL* self, PyObject* args) { const char* s; - unsigned long i; + long long i; PyObject* bytes = NULL; // The constructor argument can be a string ("1234"), an integer (1), // or a sequence of numbers between 0 and 255 (wire code) @@ -158,10 +158,10 @@ RRTTL_init(s_RRTTL* self, PyObject* args) { if (PyArg_ParseTuple(args, "s", &s)) { self->rrttl = new RRTTL(s); return (0); - } else if (PyArg_ParseTuple(args, "k", &i)) { + } else if (PyArg_ParseTuple(args, "L", &i)) { PyErr_Clear(); - if (i > 0xffffffff) { - PyErr_SetString(po_InvalidRRTTL, "RR TTL number out of range"); + if (i < 0 || i > 0xffffffff) { + PyErr_SetString(PyExc_ValueError, "RR TTL number out of range"); return (-1); } self->rrttl = new RRTTL(i); diff --git a/src/lib/dns/python/rrtype_python.cc b/src/lib/dns/python/rrtype_python.cc index 19af8c1314..12f50c1fd8 100644 --- a/src/lib/dns/python/rrtype_python.cc +++ b/src/lib/dns/python/rrtype_python.cc @@ -198,7 +198,7 @@ RRType_init(s_RRType* self, PyObject* args) { } else if (PyArg_ParseTuple(args, "l", &i)) { PyErr_Clear(); if (i < 0 || i > 0xffff) { - PyErr_SetString(PyExc_OverflowError, "RR Type number out of range"); + PyErr_SetString(PyExc_ValueError, "RR Type number out of range"); return (-1); } self->rrtype = new RRType(i); diff --git a/src/lib/dns/python/tests/edns_python_test.py b/src/lib/dns/python/tests/edns_python_test.py index 13aa2f0548..730f39e869 100644 --- a/src/lib/dns/python/tests/edns_python_test.py +++ b/src/lib/dns/python/tests/edns_python_test.py @@ -71,8 +71,8 @@ class EDNSTest(unittest.TestCase): # Range check. We need to do this at the binding level, so we need # explicit tests for it. - self.assertRaises(OverflowError, edns.set_udp_size, 0x10000) - self.assertRaises(OverflowError, edns.set_udp_size, -1) + self.assertRaises(ValueError, edns.set_udp_size, 0x10000) + self.assertRaises(ValueError, edns.set_udp_size, -1) def test_get_version(self): self.assertEqual(EDNS.SUPPORTED_VERSION, EDNS().get_version()) diff --git a/src/lib/dns/python/tests/message_python_test.py b/src/lib/dns/python/tests/message_python_test.py index 2850c8ca91..e42dd98c6b 100644 --- a/src/lib/dns/python/tests/message_python_test.py +++ b/src/lib/dns/python/tests/message_python_test.py @@ -111,17 +111,17 @@ class MessageTest(unittest.TestCase): self.assertRaises(InvalidParameter, self.r.set_header_flag, 0) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x7000) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x0800) - # this would cause overflow - self.assertRaises(OverflowError, self.r.set_header_flag, 0x10000) - self.assertRaises(OverflowError, self.r.set_header_flag, -1) + # this would cause out of range + self.assertRaises(ValueError, self.r.set_header_flag, 0x10000) + self.assertRaises(ValueError, self.r.set_header_flag, -1) self.assertRaises(InvalidMessageOperation, self.p.set_header_flag, Message.HEADERFLAG_AA) def test_set_qid(self): self.assertRaises(TypeError, self.r.set_qid, "wrong") - self.assertRaises(OverflowError, self.r.set_qid, -1) - self.assertRaises(OverflowError, self.r.set_qid, 0x10000) + self.assertRaises(ValueError, self.r.set_qid, -1) + self.assertRaises(ValueError, self.r.set_qid, 0x10000) self.assertRaises(InvalidMessageOperation, self.p.set_qid, 123) diff --git a/src/lib/dns/python/tests/messagerenderer_python_test.py b/src/lib/dns/python/tests/messagerenderer_python_test.py index b77941fa3c..540064bfa8 100644 --- a/src/lib/dns/python/tests/messagerenderer_python_test.py +++ b/src/lib/dns/python/tests/messagerenderer_python_test.py @@ -98,8 +98,8 @@ class MessageRendererTest(unittest.TestCase): renderer.set_length_limit(1024) self.assertEqual(1024, renderer.get_length_limit()) self.assertRaises(TypeError, renderer.set_length_limit, "wrong") - self.assertRaises(OverflowError, renderer.set_length_limit, -1) - self.assertRaises(OverflowError, renderer.set_length_limit, 0x10000) + self.assertRaises(ValueError, renderer.set_length_limit, -1) + self.assertRaises(ValueError, renderer.set_length_limit, 0x10000) def test_messagerenderer_set_compress_mode(self): renderer = MessageRenderer() diff --git a/src/lib/dns/python/tests/name_python_test.py b/src/lib/dns/python/tests/name_python_test.py index e0482a96ba..7ea262867a 100644 --- a/src/lib/dns/python/tests/name_python_test.py +++ b/src/lib/dns/python/tests/name_python_test.py @@ -95,15 +95,15 @@ class NameTest(unittest.TestCase): b = bytearray() b += b'\x07example'*32 + b'\x03com\x00' self.assertRaises(DNSMessageFORMERR, Name, b, 0) - self.assertRaises(TypeError, Name, b, -1) + self.assertRaises(IndexError, Name, b, -1) def test_at(self): self.assertEqual(7, self.name1.at(0)) self.assertEqual(101, self.name1.at(1)) self.assertRaises(IndexError, self.name1.at, 100) + self.assertRaises(IndexError, self.name1.at, 0x10000) + self.assertRaises(IndexError, self.name1.at, -1) self.assertRaises(TypeError, self.name1.at, "wrong") - self.assertRaises(OverflowError, self.name1.at, -1) - self.assertRaises(OverflowError, self.name1.at, 0x10000) def test_get_length(self): self.assertEqual(13, self.name1.get_length()) @@ -156,20 +156,18 @@ class NameTest(unittest.TestCase): self.assertRaises(TypeError, self.name1.split, 1, "wrong") self.assertRaises(IndexError, self.name1.split, 123, 1) self.assertRaises(IndexError, self.name1.split, 1, 123) - # Out of range - self.assertRaises(OverflowError, self.name1.split, -1, 123) - self.assertRaises(OverflowError, self.name1.split, 0, -1) - self.assertRaises(OverflowError, self.name1.split, 1, 0x10000) - self.assertRaises(OverflowError, self.name1.split, 0x10000, 5) + self.assertRaises(IndexError, self.name1.split, 0x10000, 5) + self.assertRaises(IndexError, self.name1.split, -1, -1) + self.assertRaises(IndexError, self.name1.split, 0, -1) + self.assertRaises(IndexError, self.name1.split, -1, 0x10000) s = self.name1.split(1) self.assertEqual("com.", s.to_text()) s = self.name1.split(0) self.assertEqual("example.com.", s.to_text()) self.assertRaises(IndexError, self.name1.split, 123) - # Out of range - self.assertRaises(OverflowError, self.name1.split, 0x10000) - self.assertRaises(OverflowError, self.name1.split, -123) + self.assertRaises(IndexError, self.name1.split, 0x10000) + self.assertRaises(IndexError, self.name1.split, -123) def test_reverse(self): self.assertEqual("com.example.", self.name1.reverse().to_text()) diff --git a/src/lib/dns/python/tests/rcode_python_test.py b/src/lib/dns/python/tests/rcode_python_test.py index 3577f84b5c..6e7ec1645a 100644 --- a/src/lib/dns/python/tests/rcode_python_test.py +++ b/src/lib/dns/python/tests/rcode_python_test.py @@ -23,7 +23,9 @@ from pydnspp import * class RcodeTest(unittest.TestCase): def test_init(self): self.assertRaises(TypeError, Rcode, "wrong") - self.assertRaises(OverflowError, Rcode, 65536) + self.assertRaises(ValueError, Rcode, 65536) + self.assertRaises(ValueError, Rcode, 0x10, 0x100) + self.assertRaises(ValueError, Rcode, 0x100, 0x10) self.assertEqual(Rcode(0).get_code(), 0) self.assertEqual(0, Rcode(0).get_code()) diff --git a/src/lib/dns/python/tests/rrclass_python_test.py b/src/lib/dns/python/tests/rrclass_python_test.py index a5a1f95502..47f9712e4a 100644 --- a/src/lib/dns/python/tests/rrclass_python_test.py +++ b/src/lib/dns/python/tests/rrclass_python_test.py @@ -32,8 +32,8 @@ class RRClassTest(unittest.TestCase): b = bytearray(1) b[0] = 123 self.assertRaises(TypeError, RRClass, b) - self.assertRaises(OverflowError, RRClass, 65536) - self.assertRaises(OverflowError, RRClass, -12) + self.assertRaises(ValueError, RRClass, 65536) + self.assertRaises(ValueError, RRClass, -12) self.assertEqual(self.c1, RRClass(1)) b = bytearray() self.c1.to_wire(b) diff --git a/src/lib/dns/python/tests/rrttl_python_test.py b/src/lib/dns/python/tests/rrttl_python_test.py index 095a0b1964..a7bde13206 100644 --- a/src/lib/dns/python/tests/rrttl_python_test.py +++ b/src/lib/dns/python/tests/rrttl_python_test.py @@ -25,7 +25,7 @@ class RRTTLTest(unittest.TestCase): def setUp(self): self.t1 = RRTTL(1) self.t2 = RRTTL(3600) - + def test_init(self): self.assertRaises(InvalidRRTTL, RRTTL, "wrong") self.assertRaises(TypeError, RRTTL, Exception()) @@ -33,13 +33,15 @@ class RRTTLTest(unittest.TestCase): b[0] = 123 self.assertRaises(IncompleteRRTTL, RRTTL, b) self.assertRaises(InvalidRRTTL, RRTTL, "4294967296") + self.assertRaises(ValueError, RRTTL, -4) + self.assertRaises(ValueError, RRTTL, 4294967296) b = bytearray(4) b[0] = 0 b[1] = 0 b[2] = 0 b[3] = 15 self.assertEqual(15, RRTTL(b).get_value()) - + def test_rrttl_to_text(self): self.assertEqual("1", self.t1.to_text()) self.assertEqual("1", str(self.t1)) diff --git a/src/lib/dns/python/tests/rrtype_python_test.py b/src/lib/dns/python/tests/rrtype_python_test.py index cd6364fdb6..f124fbc6b4 100644 --- a/src/lib/dns/python/tests/rrtype_python_test.py +++ b/src/lib/dns/python/tests/rrtype_python_test.py @@ -32,7 +32,7 @@ class TestModuleSpec(unittest.TestCase): def test_init(self): - self.assertRaises(OverflowError, RRType, 65537) + self.assertRaises(ValueError, RRType, 65537) b = bytearray(b'\x00\x01') self.assertEqual(RRType("A"), RRType(b)) b = bytearray(b'\x01') From 4a484575725500dd766516377eda41daaa17f402 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Fri, 18 Mar 2011 20:16:42 +0100 Subject: [PATCH 30/72] [trac615] XfrOut can use different socket --- configure.ac | 1 + .../{xfrout_test.py => xfrout_test.py.in} | 32 +++++++++++++++++ src/bin/xfrout/xfrout.py.in | 35 ++++++++++++------- 3 files changed, 55 insertions(+), 13 deletions(-) rename src/bin/xfrout/tests/{xfrout_test.py => xfrout_test.py.in} (93%) diff --git a/configure.ac b/configure.ac index 7f2b3eac4a..fd6dd4277d 100644 --- a/configure.ac +++ b/configure.ac @@ -706,6 +706,7 @@ AC_OUTPUT([doc/version.ent src/bin/xfrout/xfrout.py src/bin/xfrout/xfrout.spec.pre src/bin/xfrout/tests/xfrout_test + src/bin/xfrout/tests/xfrout_test.py src/bin/xfrout/run_b10-xfrout.sh src/bin/resolver/resolver.spec.pre src/bin/resolver/spec_config.h.pre diff --git a/src/bin/xfrout/tests/xfrout_test.py b/src/bin/xfrout/tests/xfrout_test.py.in similarity index 93% rename from src/bin/xfrout/tests/xfrout_test.py rename to src/bin/xfrout/tests/xfrout_test.py.in index 5aec072228..472ef3cdd4 100644 --- a/src/bin/xfrout/tests/xfrout_test.py +++ b/src/bin/xfrout/tests/xfrout_test.py.in @@ -21,6 +21,7 @@ import os from isc.cc.session import * from pydnspp import * from xfrout import * +import xfrout # our fake socket, where we can read and insert messages class MySocket(): @@ -433,5 +434,36 @@ class TestUnixSockServer(unittest.TestCase): sys.stdout = old_stdout os.rmdir(dir_name) +class TestInitialization(unittest.TestCase): + def setEnv(self, name, value): + if value is None: + if name in os.environ: + del os.environ[name] + else: + os.environ[name] = value + + def setUp(self): + self._oldSocket = os.getenv("BIND10_XFROUT_SOCKET_FILE") + self._oldFromBuild = os.getenv("B10_FROM_BUILD") + + def tearDown(self): + self.setEnv("B10_FROM_BUILD", self._oldFromBuild) + self.setEnv("BIND10_XFROUT_SOCKET_FILE", self._oldSocket) + # Make sure even the computed values are back + xfrout.init_paths() + + def testNoEnv(self): + self.setEnv("B10_FROM_BUILD", None) + self.setEnv("BIND10_XFROUT_SOCKET_FILE", None) + xfrout.init_paths() + self.assertEqual(xfrout.UNIX_SOCKET_FILE, + "@@LOCALSTATEDIR@@/auth_xfrout_conn") + + def testProvidedSocket(self): + self.setEnv("B10_FROM_BUILD", None) + self.setEnv("BIND10_XFROUT_SOCKET_FILE", "The/Socket/File") + xfrout.init_paths() + self.assertEqual(xfrout.UNIX_SOCKET_FILE, "The/Socket/File") + if __name__== "__main__": unittest.main() diff --git a/src/bin/xfrout/xfrout.py.in b/src/bin/xfrout/xfrout.py.in index b3f9e95d89..44df8abcc4 100755 --- a/src/bin/xfrout/xfrout.py.in +++ b/src/bin/xfrout/xfrout.py.in @@ -46,20 +46,29 @@ except ImportError as e: isc.util.process.rename() -if "B10_FROM_BUILD" in os.environ: - SPECFILE_PATH = os.environ["B10_FROM_BUILD"] + "/src/bin/xfrout" - AUTH_SPECFILE_PATH = os.environ["B10_FROM_BUILD"] + "/src/bin/auth" - if "B10_FROM_SOURCE_LOCALSTATEDIR" in os.environ: - UNIX_SOCKET_FILE = os.environ["B10_FROM_SOURCE_LOCALSTATEDIR"] + \ - "/auth_xfrout_conn" +def init_paths(): + global SPECFILE_PATH + global AUTH_SPECFILE_PATH + global UNIX_SOCKET_FILE + if "B10_FROM_BUILD" in os.environ: + SPECFILE_PATH = os.environ["B10_FROM_BUILD"] + "/src/bin/xfrout" + AUTH_SPECFILE_PATH = os.environ["B10_FROM_BUILD"] + "/src/bin/auth" + if "B10_FROM_SOURCE_LOCALSTATEDIR" in os.environ: + UNIX_SOCKET_FILE = os.environ["B10_FROM_SOURCE_LOCALSTATEDIR"] + \ + "/auth_xfrout_conn" + else: + UNIX_SOCKET_FILE = os.environ["B10_FROM_BUILD"] + "/auth_xfrout_conn" else: - UNIX_SOCKET_FILE = os.environ["B10_FROM_BUILD"] + "/auth_xfrout_conn" -else: - PREFIX = "@prefix@" - DATAROOTDIR = "@datarootdir@" - SPECFILE_PATH = "@datadir@/@PACKAGE@".replace("${datarootdir}", DATAROOTDIR).replace("${prefix}", PREFIX) - AUTH_SPECFILE_PATH = SPECFILE_PATH - UNIX_SOCKET_FILE = "@@LOCALSTATEDIR@@/auth_xfrout_conn" + PREFIX = "@prefix@" + DATAROOTDIR = "@datarootdir@" + SPECFILE_PATH = "@datadir@/@PACKAGE@".replace("${datarootdir}", DATAROOTDIR).replace("${prefix}", PREFIX) + AUTH_SPECFILE_PATH = SPECFILE_PATH + if "BIND10_XFROUT_SOCKET_FILE" in os.environ: + UNIX_SOCKET_FILE = os.environ["BIND10_XFROUT_SOCKET_FILE"] + else: + UNIX_SOCKET_FILE = "@@LOCALSTATEDIR@@/auth_xfrout_conn" + +init_paths() SPECFILE_LOCATION = SPECFILE_PATH + "/xfrout.spec" AUTH_SPECFILE_LOCATION = AUTH_SPECFILE_PATH + os.sep + "auth.spec" From eddf905784249ab6949e6186f2676f9d627b089c Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Mon, 28 Mar 2011 11:01:30 +0200 Subject: [PATCH 31/72] [trac366] Update old copyrights --- src/bin/sockcreator/main.cc | 2 +- src/bin/sockcreator/sockcreator.cc | 2 +- src/bin/sockcreator/sockcreator.h | 2 +- src/bin/sockcreator/tests/run_unittests.cc | 2 +- src/bin/sockcreator/tests/sockcreator_tests.cc | 2 +- src/lib/util/io/fd.cc | 2 +- src/lib/util/io/fd.h | 2 +- src/lib/util/io/tests/fd_share_tests.cc | 2 +- src/lib/util/io/tests/fd_tests.cc | 2 +- src/lib/util/io/tests/run_unittests.cc | 2 +- src/lib/util/unittests/fork.cc | 2 +- src/lib/util/unittests/fork.h | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bin/sockcreator/main.cc b/src/bin/sockcreator/main.cc index 09ee3cbc72..37da30394d 100644 --- a/src/bin/sockcreator/main.cc +++ b/src/bin/sockcreator/main.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index f35b5cb121..76f6e94e83 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h index 0685800c28..ddf9a090d7 100644 --- a/src/bin/sockcreator/sockcreator.h +++ b/src/bin/sockcreator/sockcreator.h @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/bin/sockcreator/tests/run_unittests.cc b/src/bin/sockcreator/tests/run_unittests.cc index 74c27b2ba5..e787ab1cb1 100644 --- a/src/bin/sockcreator/tests/run_unittests.cc +++ b/src/bin/sockcreator/tests/run_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index 09c16e1093..cfdaa8da2d 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/util/io/fd.cc b/src/lib/util/io/fd.cc index 7ae8619020..04e64dcd39 100644 --- a/src/lib/util/io/fd.cc +++ b/src/lib/util/io/fd.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/util/io/fd.h b/src/lib/util/io/fd.h index a19ca26799..bdd2d41f58 100644 --- a/src/lib/util/io/fd.h +++ b/src/lib/util/io/fd.h @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/util/io/tests/fd_share_tests.cc b/src/lib/util/io/tests/fd_share_tests.cc index 88a00156aa..0902ce08b3 100644 --- a/src/lib/util/io/tests/fd_share_tests.cc +++ b/src/lib/util/io/tests/fd_share_tests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/util/io/tests/fd_tests.cc b/src/lib/util/io/tests/fd_tests.cc index 1953077537..12b70d8b49 100644 --- a/src/lib/util/io/tests/fd_tests.cc +++ b/src/lib/util/io/tests/fd_tests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/util/io/tests/run_unittests.cc b/src/lib/util/io/tests/run_unittests.cc index 74c27b2ba5..e787ab1cb1 100644 --- a/src/lib/util/io/tests/run_unittests.cc +++ b/src/lib/util/io/tests/run_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/util/unittests/fork.cc b/src/lib/util/unittests/fork.cc index 2b665a231b..bfced896b4 100644 --- a/src/lib/util/unittests/fork.cc +++ b/src/lib/util/unittests/fork.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/util/unittests/fork.h b/src/lib/util/unittests/fork.h index 55cff68000..3331cfabc2 100644 --- a/src/lib/util/unittests/fork.h +++ b/src/lib/util/unittests/fork.h @@ -1,4 +1,4 @@ -// Copyright (C) 2010 CZ NIC +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above From 13668e95ca6bbb07128babb14f1772bfefcb09a8 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Mon, 28 Mar 2011 11:30:13 +0200 Subject: [PATCH 32/72] [trac366] Fix tests It needed very large stack, causing a stack overflow sometimes. --- src/lib/util/unittests/fork.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/util/unittests/fork.cc b/src/lib/util/unittests/fork.cc index bfced896b4..1eeb2cc7a5 100644 --- a/src/lib/util/unittests/fork.cc +++ b/src/lib/util/unittests/fork.cc @@ -47,7 +47,8 @@ process_ok(pid_t process) { if (sigaction(SIGALRM, &ignored, &original)) { return false; } - alarm(3); + // It is long, but if everything is OK, it'll not happen + alarm(10); int status; int result(waitpid(process, &status, 0) == -1); // Cancel the alarm and return the original handler @@ -104,10 +105,13 @@ check_output(int *write_pipe, const void *output, const size_t length) *write_pipe = pipes[1]; pid_t pid(fork()); if (pid) { // We are in parent + close(pipes[0]); return pid; } else { close(pipes[1]); - unsigned char buffer[length + 1]; + // We don't return the memory, but we're in tests and end this process + // right away. + unsigned char *buffer = new unsigned char[length + 1]; // Try to read one byte more to see if the output ends here size_t got_length(read_data(pipes[0], buffer, length + 1)); bool ok(true); @@ -120,7 +124,7 @@ check_output(int *write_pipe, const void *output, const size_t length) if(!ok || memcmp(buffer, output, length)) { const unsigned char *output_c(static_cast( output)); - // If the differ, print what we have + // If they differ, print what we have for(size_t i(0); i != got_length; ++ i) { fprintf(stderr, "%02hhx", buffer[i]); } From a3f3377467d511fb0e789957a4b7a9105e4fe0d2 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Wed, 6 Apr 2011 12:59:54 +0200 Subject: [PATCH 33/72] [trac615] Tests for path setup in auth --- src/bin/auth/Makefile.am | 2 +- src/bin/auth/common.cc | 32 +++++++++ src/bin/auth/common.h | 11 ++- src/bin/auth/main.cc | 16 +---- src/bin/auth/tests/Makefile.am | 2 + src/bin/auth/tests/common_unittest.cc | 96 +++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 16 deletions(-) create mode 100644 src/bin/auth/common.cc create mode 100644 src/bin/auth/tests/common_unittest.cc diff --git a/src/bin/auth/Makefile.am b/src/bin/auth/Makefile.am index cdfc55eef8..e6fbf239c4 100644 --- a/src/bin/auth/Makefile.am +++ b/src/bin/auth/Makefile.am @@ -41,7 +41,7 @@ b10_auth_SOURCES += auth_srv.cc auth_srv.h b10_auth_SOURCES += change_user.cc change_user.h b10_auth_SOURCES += config.cc config.h b10_auth_SOURCES += command.cc command.h -b10_auth_SOURCES += common.h +b10_auth_SOURCES += common.h common.cc b10_auth_SOURCES += statistics.cc statistics.h b10_auth_SOURCES += main.cc b10_auth_LDADD = $(top_builddir)/src/lib/datasrc/libdatasrc.la diff --git a/src/bin/auth/common.cc b/src/bin/auth/common.cc new file mode 100644 index 0000000000..811db63fbf --- /dev/null +++ b/src/bin/auth/common.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2009-2011 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include +#include + +using std::string; + +string getXfroutSocketPath() { + if (getenv("B10_FROM_BUILD") != NULL) { + if (getenv("B10_FROM_SOURCE_LOCALSTATEDIR")) { + return (string("B10_FROM_SOURCE_LOCALSTATEDIR") + + "/auth_xfrout_conn"); + } else { + return (string(getenv("B10_FROM_BUILD")) + "/auth_xfrout_conn"); + } + } else { + return (UNIX_SOCKET_FILE); + } +} diff --git a/src/bin/auth/common.h b/src/bin/auth/common.h index 6af09fbe98..b913593baa 100644 --- a/src/bin/auth/common.h +++ b/src/bin/auth/common.h @@ -1,4 +1,4 @@ -// Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2009-2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -29,6 +29,15 @@ public: {} }; +/// \short Get the path of socket to talk to xfrout +/// +/// It takes some environment variables into account (B10_FROM_BUILD, +/// B10_FROM_SOURCE_LOCALSTATEDIR and BIND10_XFROUT_SOCKET_FILE). It +/// also considers the installation prefix. +/// +/// The logic should be the same as in b10-xfrout, so they find each other. +std::string getXfroutSocketPath(); + #endif // __COMMON_H // Local Variables: diff --git a/src/bin/auth/main.cc b/src/bin/auth/main.cc index fad4a727fa..23b8902e78 100644 --- a/src/bin/auth/main.cc +++ b/src/bin/auth/main.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2009-2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -120,19 +120,7 @@ main(int argc, char* argv[]) { bool xfrin_session_established = false; // XXX (see Trac #287) bool statistics_session_established = false; // XXX (see Trac #287) ModuleCCSession* config_session = NULL; - string xfrout_socket_path; - if (getenv("B10_FROM_BUILD") != NULL) { - if (getenv("B10_FROM_SOURCE_LOCALSTATEDIR")) { - xfrout_socket_path = string("B10_FROM_SOURCE_LOCALSTATEDIR") + - "/auth_xfrout_conn"; - } else { - xfrout_socket_path = string(getenv("B10_FROM_BUILD")) + - "/auth_xfrout_conn"; - } - } else { - xfrout_socket_path = UNIX_SOCKET_FILE; - } - XfroutClient xfrout_client(xfrout_socket_path); + XfroutClient xfrout_client(getXfroutSocketPath()); try { string specfile; if (getenv("B10_FROM_BUILD")) { diff --git a/src/bin/auth/tests/Makefile.am b/src/bin/auth/tests/Makefile.am index 7d489a1995..ebcd612868 100644 --- a/src/bin/auth/tests/Makefile.am +++ b/src/bin/auth/tests/Makefile.am @@ -24,10 +24,12 @@ run_unittests_SOURCES += ../query.h ../query.cc run_unittests_SOURCES += ../change_user.h ../change_user.cc run_unittests_SOURCES += ../config.h ../config.cc run_unittests_SOURCES += ../command.h ../command.cc +run_unittests_SOURCES += ../common.h ../common.cc run_unittests_SOURCES += ../statistics.h ../statistics.cc run_unittests_SOURCES += auth_srv_unittest.cc run_unittests_SOURCES += config_unittest.cc run_unittests_SOURCES += command_unittest.cc +run_unittests_SOURCES += common_unittest.cc run_unittests_SOURCES += query_unittest.cc run_unittests_SOURCES += change_user_unittest.cc run_unittests_SOURCES += statistics_unittest.cc diff --git a/src/bin/auth/tests/common_unittest.cc b/src/bin/auth/tests/common_unittest.cc new file mode 100644 index 0000000000..9b18142dcc --- /dev/null +++ b/src/bin/auth/tests/common_unittest.cc @@ -0,0 +1,96 @@ +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include +#include +#include +#include +#include +#include + +using std::pair; +using std::vector; +using std::string; + +namespace { + +class Paths : public ::testing::Test { +private: + typedef pair Environ; + vector restoreEnviron; +public: + void TearDown() { + // Restore the original environment + BOOST_FOREACH(const Environ &env, restoreEnviron) { + if (env.second == NULL) { + EXPECT_EQ(0, unsetenv(env.first.c_str())) << + "Couldn't restore environment, results of other tests" + "are uncertain"; + } else { + EXPECT_EQ(0, setenv(env.first.c_str(), env.second->c_str(), + 1)) << "Couldn't restore environment, " + "results of other tests are uncertain"; + } + } + } +protected: + // Sets a temporary value into environment. If value is empty, it deletes + // the variable from environment (just for simplicity). + void setEnv(const string& name, const string& value) { + // Backup the original environment + char* env(getenv(name.c_str())); + restoreEnviron.push_back(Environ(name, env == NULL ? NULL : + new string(env))); + // Set the new value + if (value.empty()) { + EXPECT_EQ(0, unsetenv(name.c_str())); + } else { + EXPECT_EQ(0, setenv(name.c_str(), value.c_str(), 1)); + } + } + // Test getXfroutSocketPath under given environment + void testXfrout(const string& fromBuild, const string& localStateDir, + const string& socketFile, const string& expected) + { + setEnv("B10_FROM_BUILD", fromBuild); + setEnv("B10_FROM_SOURCE_LOCALSTATEDIR", localStateDir); + setEnv("BIND10_XFROUT_SOCKET_FILE", socketFile); + EXPECT_EQ(expected, getXfroutSocketPath()); + } +}; + +// Test that when we have no special environment, we get the default from prefix +TEST_F(Paths, xfroutNoEnv) { + testXfrout("", "", "", UNIX_SOCKET_FILE); +} + +// Override by B10_FROM_BUILD +TEST_F(Paths, xfroutFromBuild) { + testXfrout("/from/build", "", "/wrong/path", + "/from/build/auth_xfrout_conn"); +} + +// Override by B10_FROM_SOURCE_LOCALSTATEDIR +TEST_F(Paths, xfroutLocalStatedir) { + testXfrout("/wrong/path", "/state/dir", "/wrong/path", + "/state/dir/auth_xfrout_conn"); +} + +// Override by BIND10_XFROUT_SOCKET_FILE explicitly +TEST_F(Paths, xfroutFromEnv) { + testXfrout("", "", "/the/path/to/file", "/the/path/to/file"); +} + +} From 7b2536d7a654ecb24d98c3c0814c7384230e81df Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Wed, 6 Apr 2011 13:02:27 +0200 Subject: [PATCH 34/72] [trac615] Support setting of xfrout socket --- src/bin/auth/common.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/auth/common.cc b/src/bin/auth/common.cc index 811db63fbf..fe383e28dd 100644 --- a/src/bin/auth/common.cc +++ b/src/bin/auth/common.cc @@ -21,12 +21,16 @@ using std::string; string getXfroutSocketPath() { if (getenv("B10_FROM_BUILD") != NULL) { if (getenv("B10_FROM_SOURCE_LOCALSTATEDIR")) { - return (string("B10_FROM_SOURCE_LOCALSTATEDIR") + + return (string(getenv("B10_FROM_SOURCE_LOCALSTATEDIR")) + "/auth_xfrout_conn"); } else { return (string(getenv("B10_FROM_BUILD")) + "/auth_xfrout_conn"); } } else { - return (UNIX_SOCKET_FILE); + if (getenv("BIND10_XFROUT_SOCKET_FILE")) { + return (getenv("BIND10_XFROUT_SOCKET_FILE")); + } else { + return (UNIX_SOCKET_FILE); + } } } From 20f12e8672c45540cd72bb5df44cf21ff3b6732f Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Wed, 6 Apr 2011 22:07:09 +0200 Subject: [PATCH 35/72] [trac366] Small fixups --- src/bin/sockcreator/README | 8 ++++---- src/bin/sockcreator/sockcreator.cc | 16 +++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/bin/sockcreator/README b/src/bin/sockcreator/README index d3abc9e4c8..84a0f6db01 100644 --- a/src/bin/sockcreator/README +++ b/src/bin/sockcreator/README @@ -33,10 +33,10 @@ must be a socket, not pipe. like hton called on them). The answer to this is either 'S' and then the socket is passed using sendmsg - if it is successful. If it fails, 'E' is returned, followed by either - 'S' or 'B' (either socket() or bind() call failed). Then there is one int - (architecture-dependent length and endianess), which is the errno value - after the failure. + if it is successful (it uses our send_fd, you can use recv_fd to read it). + If it fails, 'E' is returned, followed by either 'S' or 'B' (either socket() + or bind() call failed). Then there is one int (architecture-dependent length + and endianess), which is the errno value after the failure. The creator may also send these messages at any time (but not in the middle of another message): diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index 76f6e94e83..b9da84fa01 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -41,15 +41,6 @@ get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len) return sock; } -int -send_fd(const int, const int) { - return 0; -} - -int -run(const int input_fd, const int output_fd, const get_sock_t get_sock, - const send_fd_t send_fd) -{ // These are macros so they can exit the function #define READ(WHERE, HOW_MANY) do { \ size_t how_many = (HOW_MANY); \ @@ -57,15 +48,22 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock, return 1; \ } \ } while (0) + #define WRITE(WHAT, HOW_MANY) do { \ if (!write_data(output_fd, (WHAT), (HOW_MANY))) { \ return 2; \ } \ } while (0) + #define DEFAULT \ default: /* Unrecognized part of protocol */ \ WRITE("FI", 2); \ return 3; + +int +run(const int input_fd, const int output_fd, const get_sock_t get_sock, + const send_fd_t send_fd) +{ for (;;) { // Read the command char command; From 21718d6ffdc3f782ffa1b5960088786da9b77e4e Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Wed, 6 Apr 2011 18:00:34 -0700 Subject: [PATCH 36/72] [trac363] cleanup: removed a white space at EOL. --- src/lib/dns/python/tests/message_python_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dns/python/tests/message_python_test.py b/src/lib/dns/python/tests/message_python_test.py index e42dd98c6b..a6dfa635aa 100644 --- a/src/lib/dns/python/tests/message_python_test.py +++ b/src/lib/dns/python/tests/message_python_test.py @@ -111,7 +111,7 @@ class MessageTest(unittest.TestCase): self.assertRaises(InvalidParameter, self.r.set_header_flag, 0) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x7000) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x0800) - # this would cause out of range + # this would cause out of range self.assertRaises(ValueError, self.r.set_header_flag, 0x10000) self.assertRaises(ValueError, self.r.set_header_flag, -1) From ba6927dc78e991f8a5c608beee4c9807895914cd Mon Sep 17 00:00:00 2001 From: chenzhengzhang Date: Thu, 7 Apr 2011 16:50:00 +0800 Subject: [PATCH 37/72] [trac363] add more boundary test cases for python wrappers --- src/lib/dns/python/messagerenderer_python.cc | 2 +- src/lib/dns/python/name_python.cc | 2 +- src/lib/dns/python/rrtype_python.cc | 4 ++-- src/lib/dns/python/tests/edns_python_test.py | 9 ++++--- .../dns/python/tests/message_python_test.py | 24 ++++++++++++------- .../tests/messagerenderer_python_test.py | 5 +++- src/lib/dns/python/tests/name_python_test.py | 11 +++++++-- src/lib/dns/python/tests/rcode_python_test.py | 19 ++++++++------- .../dns/python/tests/rrclass_python_test.py | 8 ++++--- src/lib/dns/python/tests/rrttl_python_test.py | 8 +++++-- .../dns/python/tests/rrtype_python_test.py | 16 ++++++++----- 11 files changed, 68 insertions(+), 40 deletions(-) diff --git a/src/lib/dns/python/messagerenderer_python.cc b/src/lib/dns/python/messagerenderer_python.cc index 73bcefc9ac..f12001d202 100644 --- a/src/lib/dns/python/messagerenderer_python.cc +++ b/src/lib/dns/python/messagerenderer_python.cc @@ -185,7 +185,7 @@ MessageRenderer_setLengthLimit(s_MessageRenderer* self, "No valid type in set_length_limit argument"); return (NULL); } - if (lengthlimit < 0 || lengthlimit > 0xffff) { + if (lengthlimit < 0) { PyErr_SetString(PyExc_ValueError, "MessageRenderer length limit out of range"); return (NULL); diff --git a/src/lib/dns/python/name_python.cc b/src/lib/dns/python/name_python.cc index 1aef2a0dbb..7d8913a758 100644 --- a/src/lib/dns/python/name_python.cc +++ b/src/lib/dns/python/name_python.cc @@ -532,7 +532,7 @@ Name_split(s_Name* self, PyObject* args) { // It is translated to a function that gets 3 arguments, an object, // an object to compare to, and an operator. // -static PyObject* +static PyObject* Name_richcmp(s_Name* self, s_Name* other, int op) { bool c; diff --git a/src/lib/dns/python/rrtype_python.cc b/src/lib/dns/python/rrtype_python.cc index 12f50c1fd8..4fc0284771 100644 --- a/src/lib/dns/python/rrtype_python.cc +++ b/src/lib/dns/python/rrtype_python.cc @@ -259,10 +259,10 @@ static PyObject* RRType_toWire(s_RRType* self, PyObject* args) { PyObject* bytes; s_MessageRenderer* mr; - + if (PyArg_ParseTuple(args, "O", &bytes) && PySequence_Check(bytes)) { PyObject* bytes_o = bytes; - + OutputBuffer buffer(2); self->rrtype->toWire(buffer); PyObject* n = PyBytes_FromStringAndSize(static_cast(buffer.getData()), buffer.getLength()); diff --git a/src/lib/dns/python/tests/edns_python_test.py b/src/lib/dns/python/tests/edns_python_test.py index 730f39e869..b249213d7a 100644 --- a/src/lib/dns/python/tests/edns_python_test.py +++ b/src/lib/dns/python/tests/edns_python_test.py @@ -62,15 +62,14 @@ class EDNSTest(unittest.TestCase): edns = EDNS() edns.set_udp_size(511) self.assertEqual(511, edns.get_udp_size()) - edns.set_udp_size(0) - self.assertEqual(0, edns.get_udp_size()) - edns.set_udp_size(65535) - self.assertEqual(65535, edns.get_udp_size()) - self.assertRaises(TypeError, edns.set_udp_size, "wrong") # Range check. We need to do this at the binding level, so we need # explicit tests for it. + edns.set_udp_size(0) + self.assertEqual(0, edns.get_udp_size()) + edns.set_udp_size(65535) + self.assertEqual(65535, edns.get_udp_size()) self.assertRaises(ValueError, edns.set_udp_size, 0x10000) self.assertRaises(ValueError, edns.set_udp_size, -1) diff --git a/src/lib/dns/python/tests/message_python_test.py b/src/lib/dns/python/tests/message_python_test.py index a6dfa635aa..bccc5968a3 100644 --- a/src/lib/dns/python/tests/message_python_test.py +++ b/src/lib/dns/python/tests/message_python_test.py @@ -111,22 +111,28 @@ class MessageTest(unittest.TestCase): self.assertRaises(InvalidParameter, self.r.set_header_flag, 0) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x7000) self.assertRaises(InvalidParameter, self.r.set_header_flag, 0x0800) - # this would cause out of range - self.assertRaises(ValueError, self.r.set_header_flag, 0x10000) - self.assertRaises(ValueError, self.r.set_header_flag, -1) - self.assertRaises(InvalidMessageOperation, self.p.set_header_flag, Message.HEADERFLAG_AA) + # Range check. We need to do this at the binding level, so we need + # explicit tests for it. + self.assertRaises(ValueError, self.r.set_header_flag, 0x10000) + self.assertRaises(ValueError, self.r.set_header_flag, -1) + def test_set_qid(self): self.assertRaises(TypeError, self.r.set_qid, "wrong") - self.assertRaises(ValueError, self.r.set_qid, -1) - self.assertRaises(ValueError, self.r.set_qid, 0x10000) self.assertRaises(InvalidMessageOperation, self.p.set_qid, 123) - self.r.set_qid(1234) self.assertEqual(1234, self.r.get_qid()) + # Range check. We need to do this at the binding level, so we need + # explicit tests for it. + self.r.set_qid(0) + self.assertEqual(0, self.r.get_qid()) + self.r.set_qid(0xffff) + self.assertEqual(0xffff, self.r.get_qid()) + self.assertRaises(ValueError, self.r.set_qid, -1) + self.assertRaises(ValueError, self.r.set_qid, 0x10000) def test_set_rcode(self): self.assertRaises(TypeError, self.r.set_rcode, "wrong") @@ -137,7 +143,7 @@ class MessageTest(unittest.TestCase): self.assertRaises(InvalidMessageOperation, self.p.set_rcode, rcode) - + self.assertRaises(InvalidMessageOperation, self.p.get_rcode) def test_set_opcode(self): @@ -199,7 +205,7 @@ class MessageTest(unittest.TestCase): self.assertRaises(InvalidMessageOperation, self.p.add_rrset, Message.SECTION_ANSWER, self.rrset_a) - + self.assertFalse(compare_rrset_list(section_rrset, self.r.get_section(Message.SECTION_ANSWER))) self.assertEqual(0, self.r.get_rr_count(Message.SECTION_ANSWER)) self.r.add_rrset(Message.SECTION_ANSWER, self.rrset_a) diff --git a/src/lib/dns/python/tests/messagerenderer_python_test.py b/src/lib/dns/python/tests/messagerenderer_python_test.py index 540064bfa8..53624964bf 100644 --- a/src/lib/dns/python/tests/messagerenderer_python_test.py +++ b/src/lib/dns/python/tests/messagerenderer_python_test.py @@ -98,8 +98,11 @@ class MessageRendererTest(unittest.TestCase): renderer.set_length_limit(1024) self.assertEqual(1024, renderer.get_length_limit()) self.assertRaises(TypeError, renderer.set_length_limit, "wrong") + # Range check. We need to do this at the binding level, so we need + # explicit tests for it. + renderer.set_length_limit(0) + self.assertEqual(0, renderer.get_length_limit()) self.assertRaises(ValueError, renderer.set_length_limit, -1) - self.assertRaises(ValueError, renderer.set_length_limit, 0x10000) def test_messagerenderer_set_compress_mode(self): renderer = MessageRenderer() diff --git a/src/lib/dns/python/tests/name_python_test.py b/src/lib/dns/python/tests/name_python_test.py index 7ea262867a..1d8d68360f 100644 --- a/src/lib/dns/python/tests/name_python_test.py +++ b/src/lib/dns/python/tests/name_python_test.py @@ -154,6 +154,14 @@ class NameTest(unittest.TestCase): self.assertEqual("completely.different.", s.to_text()) self.assertRaises(TypeError, self.name1.split, "wrong", 1) self.assertRaises(TypeError, self.name1.split, 1, "wrong") + + s = self.name1.split(0) + self.assertEqual("example.com.", s.to_text()) + s = self.name1.split(1) + self.assertEqual("com.", s.to_text()) + + # Range check. We need to do this at the binding level, so we need + # explicit tests for it. self.assertRaises(IndexError, self.name1.split, 123, 1) self.assertRaises(IndexError, self.name1.split, 1, 123) self.assertRaises(IndexError, self.name1.split, 0x10000, 5) @@ -161,13 +169,12 @@ class NameTest(unittest.TestCase): self.assertRaises(IndexError, self.name1.split, 0, -1) self.assertRaises(IndexError, self.name1.split, -1, 0x10000) - s = self.name1.split(1) - self.assertEqual("com.", s.to_text()) s = self.name1.split(0) self.assertEqual("example.com.", s.to_text()) self.assertRaises(IndexError, self.name1.split, 123) self.assertRaises(IndexError, self.name1.split, 0x10000) self.assertRaises(IndexError, self.name1.split, -123) + self.assertRaises(TypeError, self.name1.split, -1) def test_reverse(self): self.assertEqual("com.example.", self.name1.reverse().to_text()) diff --git a/src/lib/dns/python/tests/rcode_python_test.py b/src/lib/dns/python/tests/rcode_python_test.py index 6e7ec1645a..27b1da806f 100644 --- a/src/lib/dns/python/tests/rcode_python_test.py +++ b/src/lib/dns/python/tests/rcode_python_test.py @@ -23,14 +23,8 @@ from pydnspp import * class RcodeTest(unittest.TestCase): def test_init(self): self.assertRaises(TypeError, Rcode, "wrong") - self.assertRaises(ValueError, Rcode, 65536) - self.assertRaises(ValueError, Rcode, 0x10, 0x100) - self.assertRaises(ValueError, Rcode, 0x100, 0x10) - self.assertEqual(Rcode(0).get_code(), 0) - - self.assertEqual(0, Rcode(0).get_code()) self.assertEqual(0xfff, Rcode(0xfff).get_code()) # possible max code - + # should fail on attempt of construction with an out of range code self.assertRaises(OverflowError, Rcode, 0x1000) self.assertRaises(OverflowError, Rcode, 0xffff) @@ -40,7 +34,16 @@ class RcodeTest(unittest.TestCase): self.assertEqual(Rcode.BADVERS_CODE, Rcode(0, 1).get_code()) self.assertEqual(0xfff, Rcode(0xf, 0xff).get_code()) self.assertRaises(OverflowError, Rcode, 0x10, 0xff) - + + # Range check. We need to do this at the binding level, so we need + # explicit tests for it. + self.assertEqual(Rcode(0).get_code(), 0) + self.assertEqual(Rcode(0, 0).get_code(), 0) + self.assertEqual(Rcode(0, 0).get_extended_code(), 0) + self.assertRaises(ValueError, Rcode, 65536) + self.assertRaises(ValueError, Rcode, 0x10, 0x100) + self.assertRaises(ValueError, Rcode, 0x100, 0x10) + def test_constants(self): self.assertEqual(Rcode.NOERROR_CODE, Rcode(0).get_code()) self.assertEqual(Rcode.FORMERR_CODE, Rcode(1).get_code()) diff --git a/src/lib/dns/python/tests/rrclass_python_test.py b/src/lib/dns/python/tests/rrclass_python_test.py index 47f9712e4a..a195cd1908 100644 --- a/src/lib/dns/python/tests/rrclass_python_test.py +++ b/src/lib/dns/python/tests/rrclass_python_test.py @@ -32,13 +32,15 @@ class RRClassTest(unittest.TestCase): b = bytearray(1) b[0] = 123 self.assertRaises(TypeError, RRClass, b) - self.assertRaises(ValueError, RRClass, 65536) - self.assertRaises(ValueError, RRClass, -12) self.assertEqual(self.c1, RRClass(1)) b = bytearray() self.c1.to_wire(b) self.assertEqual(self.c1, RRClass(b)) - + # Range check. We need to do this at the binding level, so we need + # explicit tests for it. + self.assertRaises(ValueError, RRClass, 65536) + self.assertRaises(TypeError, RRClass, -1) + def test_rrclass_to_text(self): self.assertEqual("IN", self.c1.to_text()) self.assertEqual("IN", str(self.c1)) diff --git a/src/lib/dns/python/tests/rrttl_python_test.py b/src/lib/dns/python/tests/rrttl_python_test.py index a7bde13206..aa4a34d5aa 100644 --- a/src/lib/dns/python/tests/rrttl_python_test.py +++ b/src/lib/dns/python/tests/rrttl_python_test.py @@ -33,14 +33,18 @@ class RRTTLTest(unittest.TestCase): b[0] = 123 self.assertRaises(IncompleteRRTTL, RRTTL, b) self.assertRaises(InvalidRRTTL, RRTTL, "4294967296") - self.assertRaises(ValueError, RRTTL, -4) - self.assertRaises(ValueError, RRTTL, 4294967296) b = bytearray(4) b[0] = 0 b[1] = 0 b[2] = 0 b[3] = 15 self.assertEqual(15, RRTTL(b).get_value()) + # Range check. We need to do this at the binding level, so we need + # explicit tests for it. + self.assertRaises(TypeError, RRTTL, -1) + self.assertRaises(ValueError, RRTTL, 4294967296) + self.assertEqual(0, RRTTL(0).get_value()) + self.assertEqual(4294967295, RRTTL(4294967295).get_value()) def test_rrttl_to_text(self): self.assertEqual("1", self.t1.to_text()) diff --git a/src/lib/dns/python/tests/rrtype_python_test.py b/src/lib/dns/python/tests/rrtype_python_test.py index f124fbc6b4..713542653a 100644 --- a/src/lib/dns/python/tests/rrtype_python_test.py +++ b/src/lib/dns/python/tests/rrtype_python_test.py @@ -22,7 +22,7 @@ import os from pydnspp import * class TestModuleSpec(unittest.TestCase): - + rrtype_1 = RRType(1) rrtype_0x80 = RRType(0x80); rrtype_0x800 = RRType(0x800); @@ -32,24 +32,28 @@ class TestModuleSpec(unittest.TestCase): def test_init(self): - self.assertRaises(ValueError, RRType, 65537) b = bytearray(b'\x00\x01') self.assertEqual(RRType("A"), RRType(b)) b = bytearray(b'\x01') self.assertRaises(IncompleteRRType, RRType, b) self.assertRaises(TypeError, RRType, Exception) - + # Range check. We need to do this at the binding level, so we need + # explicit tests for it. + self.assertRaises(ValueError, RRType, 65536) + self.assertRaises(TypeError, RRType, -1) + self.assertEqual("TYPE65535", RRType(65535).to_text()); + self.assertEqual("TYPE0", RRType(0).to_text()); + def test_init_from_text(self): self.assertEqual("A", RRType("A").to_text()) self.assertEqual("NS", RRType("NS").to_text()); self.assertEqual("NS", str(RRType("NS"))); - self.assertEqual("TYPE65535", RRType("TYPE65535").to_text()); - + self.assertEqual(53, RRType("TYPE00053").get_code()); self.assertRaises(InvalidRRType, RRType, "TYPE000053"); - + self.assertRaises(InvalidRRType, RRType, "TYPE"); self.assertRaises(InvalidRRType, RRType, "TYPE-1"); self.assertRaises(InvalidRRType, RRType, "TYPExxx"); From d12560d1714fb3a07e56b6903141d82d6081148d Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Thu, 7 Apr 2011 11:32:33 +0200 Subject: [PATCH 38/72] [trac366] README tweaks --- src/bin/sockcreator/README | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bin/sockcreator/README b/src/bin/sockcreator/README index 84a0f6db01..4dbbee726e 100644 --- a/src/bin/sockcreator/README +++ b/src/bin/sockcreator/README @@ -32,11 +32,11 @@ must be a socket, not pipe. they would be passed to bind (note that both parameters are already prepared, like hton called on them). - The answer to this is either 'S' and then the socket is passed using sendmsg - if it is successful (it uses our send_fd, you can use recv_fd to read it). - If it fails, 'E' is returned, followed by either 'S' or 'B' (either socket() - or bind() call failed). Then there is one int (architecture-dependent length - and endianess), which is the errno value after the failure. + The answer to this is either 'S' directly followed by the socket (using + sendmsg) if it is successful. If it fails, 'E' is returned instead, followed + by either 'S' or 'B' (either socket() or bind() call failed). Then there is + one int (architecture-dependent length and endianess), which is the errno + value after the failure. The creator may also send these messages at any time (but not in the middle of another message): From 745b08afcdce71ca9b50b2d5a7ffe5d4ffa66091 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Thu, 7 Apr 2011 11:36:34 +0200 Subject: [PATCH 39/72] Changelog --- ChangeLog | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5ddfe3dd30..4dc8d3e76b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,16 @@ + 215. [func] vorner + A new process, b10-sockcreator, is added, which will create sockets for + the rest of the system. It is the only part which will need to keep the + root privileges. However, only the process exists, nothing can talk to it + yet. + (Trac #366, git b509cbb77d31e388df68dfe52709d6edef93df3f) + 214. [func]* vorner Zone manager no longer thinks it is secondary master for all zones in the database. They are listed in Zonemgr/secondary_zones configuration variable (in the form [{"name": "example.com", "class": "IN"}]). - (Trac #670, 7c1e4d5e1e28e556b1d10a8df8d9486971a3f052) + (Trac #670, git 7c1e4d5e1e28e556b1d10a8df8d9486971a3f052) 213. [bug] naokikambe Solved incorrect datetime of "bind10.boot_time" and also added a new From 3b6ddc0b213a61abf826d87351d97de9145a3fc4 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Thu, 7 Apr 2011 11:47:54 +0200 Subject: [PATCH 40/72] Changelog --- ChangeLog | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4dc8d3e76b..3f0d24d6d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ + 216. [func] vorner + The BIND10_XFROUT_SOCKET_FILE environment variable can be used to specify + which socket should be used for communication between b10-auth and + b10-xfrout. Mostly for testing reasons. + (Trac #615, git 28b01ad5bf72472c824a7b8fc4a8dc394e22e462) + 215. [func] vorner A new process, b10-sockcreator, is added, which will create sockets for the rest of the system. It is the only part which will need to keep the @@ -29,7 +35,7 @@ 211. [func] shane Implement "--brittle" option, which causes the server to exit - if any of BIND 10's processes dies. + if any of BIND 10's processes dies. (Trac #788, git 88c0d241fe05e5ea91b10f046f307177cc2f5bc5) 210. [bug] jerry From aac391dda57b88507b8b10ac4bd1b068d3701b2d Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Thu, 7 Apr 2011 12:39:00 +0200 Subject: [PATCH 41/72] [trac536] Handle empty buffers --- src/lib/dns/buffer.h | 4 ++-- src/lib/dns/tests/buffer_unittest.cc | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h index 39ca00bc3e..1739d9dc77 100644 --- a/src/lib/dns/buffer.h +++ b/src/lib/dns/buffer.h @@ -296,7 +296,7 @@ public: // We use malloc and free instead of C++ new[] and delete[]. // This way we can use realloc, which may in fact do it without a copy. buffer_ = static_cast(malloc(allocated_)); - if (buffer_ == NULL) { + if (buffer_ == NULL && len != 0) { throw std::bad_alloc(); } } @@ -308,7 +308,7 @@ public: allocated_(other.allocated_) { buffer_ = static_cast(malloc(allocated_)); - if (buffer_ == NULL) { + if (buffer_ == NULL && allocated_ != 0) { throw std::bad_alloc(); } memcpy(buffer_, other.buffer_, size_); diff --git a/src/lib/dns/tests/buffer_unittest.cc b/src/lib/dns/tests/buffer_unittest.cc index 2d6ffcb61b..bb6c366cb7 100644 --- a/src/lib/dns/tests/buffer_unittest.cc +++ b/src/lib/dns/tests/buffer_unittest.cc @@ -219,4 +219,12 @@ TEST_F(BufferTest, outputBufferAssign) { }); } +TEST_F(BufferTest, outputBufferZeroSize) { + // Some OSes might return NULL on malloc for 0 size, so check it works + EXPECT_NO_THROW({ + OutputBuffer first(0); + OutputBuffer copy(first); + }); +} + } From 865d62e9e58a3acf270f163a75ba713c134d82d2 Mon Sep 17 00:00:00 2001 From: Shane Kerr Date: Thu, 7 Apr 2011 15:16:46 +0200 Subject: [PATCH 42/72] Added check for another malloc() that might try to allocate 0 bytes. --- src/lib/dns/buffer.h | 2 +- src/lib/dns/tests/buffer_unittest.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h index 1739d9dc77..caf1b62dfe 100644 --- a/src/lib/dns/buffer.h +++ b/src/lib/dns/buffer.h @@ -323,7 +323,7 @@ public: /// \brief Assignment operator OutputBuffer& operator =(const OutputBuffer& other) { uint8_t* newbuff(static_cast(malloc(other.allocated_))); - if (newbuff == NULL) { + if (newbuff == NULL && other.allocated_ != 0) { throw std::bad_alloc(); } free(buffer_); diff --git a/src/lib/dns/tests/buffer_unittest.cc b/src/lib/dns/tests/buffer_unittest.cc index bb6c366cb7..65e1e96f6f 100644 --- a/src/lib/dns/tests/buffer_unittest.cc +++ b/src/lib/dns/tests/buffer_unittest.cc @@ -224,6 +224,8 @@ TEST_F(BufferTest, outputBufferZeroSize) { EXPECT_NO_THROW({ OutputBuffer first(0); OutputBuffer copy(first); + OutputBuffer second(0); + second = first; }); } From 86ab4d3fabd2e551f90603d81ff2bce2368ea7af Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Thu, 7 Apr 2011 17:02:44 +0200 Subject: [PATCH 43/72] [master] Hopefully fix Makefile It failed to build a test, because the file was generated in another directory and probably didn't yet exist at the time. --- src/bin/auth/tests/Makefile.am | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bin/auth/tests/Makefile.am b/src/bin/auth/tests/Makefile.am index 0e37da57ba..22c9c02915 100644 --- a/src/bin/auth/tests/Makefile.am +++ b/src/bin/auth/tests/Makefile.am @@ -16,6 +16,12 @@ CLEANFILES = *.gcno *.gcda TESTS = if HAVE_GTEST +../spec_config.h: ../spec_config.h.pre + $(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" spec_config.h.pre >$@ + +CLEANFILES += ../spec_config.h + +BUILT_SOURCES = ../spec_config.h TESTS += run_unittests run_unittests_SOURCES = $(top_srcdir)/src/lib/dns/tests/unittest_util.h run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.cc @@ -25,6 +31,7 @@ run_unittests_SOURCES += ../change_user.h ../change_user.cc run_unittests_SOURCES += ../auth_config.h ../auth_config.cc run_unittests_SOURCES += ../command.h ../command.cc run_unittests_SOURCES += ../common.h ../common.cc +run_unittests_SOURCES += ../spec_config.h run_unittests_SOURCES += ../statistics.h ../statistics.cc run_unittests_SOURCES += auth_srv_unittest.cc run_unittests_SOURCES += config_unittest.cc From 433ef14c7c54f255b302ff74213a24bdc298f2a0 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Thu, 7 Apr 2011 08:39:09 -0700 Subject: [PATCH 44/72] [master] updated copyright year for the template files to be a more reasonable base of real source files based on the templates. (should be trivial cleanup skipping review) --- src/lib/dns/rdata/template.cc | 2 +- src/lib/dns/rdata/template.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/dns/rdata/template.cc b/src/lib/dns/rdata/template.cc index 0e0bf46cbf..b737f6092d 100644 --- a/src/lib/dns/rdata/template.cc +++ b/src/lib/dns/rdata/template.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above diff --git a/src/lib/dns/rdata/template.h b/src/lib/dns/rdata/template.h index e85a8399f0..9e84cc31db 100644 --- a/src/lib/dns/rdata/template.h +++ b/src/lib/dns/rdata/template.h @@ -1,4 +1,4 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above From d622e35a3d7b378f79dc4d587156cbfec3befed9 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Thu, 7 Apr 2011 20:40:48 +0200 Subject: [PATCH 45/72] [master] Adapt new function after merge This function was introduced after the branch was created, but the changes are the same as with other functions - pushing directly. --- src/lib/dns/buffer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h index c451f1bc52..6fbbdb1e37 100644 --- a/src/lib/dns/buffer.h +++ b/src/lib/dns/buffer.h @@ -416,10 +416,10 @@ public: /// \param data The 8-bit integer to be written into the buffer. /// \param pos The position in the buffer to write the data. void writeUint8At(uint8_t data, size_t pos) { - if (pos + sizeof(data) > data_.size()) { + if (pos + sizeof(data) > size_) { isc_throw(InvalidBufferPosition, "write at invalid position"); } - data_[pos] = data; + buffer_[pos] = data; } /// \brief Write an unsigned 16-bit integer in host byte order into the From 778e7b5aa3c55ffc7947454459fd02263725303d Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Thu, 7 Apr 2011 21:54:05 +0200 Subject: [PATCH 46/72] [master] Provide more info on failure --- src/bin/sockcreator/tests/sockcreator_tests.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index cfdaa8da2d..f781332949 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -57,7 +57,7 @@ namespace { /* Provide even nice error message. */ \ ASSERT_GE(socket, 0) << "Couldn't create a socket of type " \ #SOCK_TYPE " and family " #ADDR_FAMILY ", failed with " \ - << socket << " and errno " << errno; \ + << socket << " and error " << strerror(errno); \ CHECK_SOCK(ADDR_TYPE, socket); \ EXPECT_EQ(0, close(socket)); \ } while (0) @@ -79,9 +79,13 @@ namespace { \ socklen_t len = sizeof addr; \ ASSERT_EQ(0, getsockname(SOCKET, addr_ptr, &len)); \ - ASSERT_EQ(5, sendto(SOCKET, "test", 5, 0, addr_ptr, sizeof addr)); \ + ASSERT_EQ(5, sendto(SOCKET, "test", 5, 0, addr_ptr, sizeof addr)) << \ + "Send failed with error " << strerror(errno) << " on socket " << \ + SOCKET; \ char buffer[5]; \ - ASSERT_EQ(5, recv(SOCKET, buffer, 5, 0)); \ + ASSERT_EQ(5, recv(SOCKET, buffer, 5, 0)) << \ + "Recv failed with error " << strerror(errno) << " on socket " << \ + SOCKET; \ EXPECT_STREQ("test", buffer); \ } while (0) From 5861ae7cb08e698c7a6c6d053b644f04106ed7a3 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Thu, 7 Apr 2011 16:26:08 -0700 Subject: [PATCH 47/72] [trac806] provide a bit more detailed information when throwing an exception due to rdlen mismatch. not directly related to the task of this ticket, but encountered a situation where it could be useful while testing. --- src/lib/dns/rdata.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/dns/rdata.cc b/src/lib/dns/rdata.cc index 17fee252f7..19b266a1e1 100644 --- a/src/lib/dns/rdata.cc +++ b/src/lib/dns/rdata.cc @@ -66,7 +66,8 @@ createRdata(const RRType& rrtype, const RRClass& rrclass, len); if (buffer.getPosition() - old_pos != len) { - isc_throw(InvalidRdataLength, "RDLENGTH mismatch"); + isc_throw(InvalidRdataLength, "RDLENGTH mismatch: " << + buffer.getPosition() - old_pos << " != " << len); } return (rdata); From ad3dfb04a335ed4c65722063bd351be51dae33b4 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Thu, 7 Apr 2011 18:06:17 -0700 Subject: [PATCH 48/72] [trac363] added some more boundary tests. --- src/lib/dns/python/tests/rcode_python_test.py | 2 ++ src/lib/dns/python/tests/rrclass_python_test.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/lib/dns/python/tests/rcode_python_test.py b/src/lib/dns/python/tests/rcode_python_test.py index 27b1da806f..77fed3a321 100644 --- a/src/lib/dns/python/tests/rcode_python_test.py +++ b/src/lib/dns/python/tests/rcode_python_test.py @@ -38,8 +38,10 @@ class RcodeTest(unittest.TestCase): # Range check. We need to do this at the binding level, so we need # explicit tests for it. self.assertEqual(Rcode(0).get_code(), 0) + self.assertEqual(Rcode(4095).get_code(), 4095) self.assertEqual(Rcode(0, 0).get_code(), 0) self.assertEqual(Rcode(0, 0).get_extended_code(), 0) + self.assertEqual(Rcode(15, 255).get_code(), 4095) self.assertRaises(ValueError, Rcode, 65536) self.assertRaises(ValueError, Rcode, 0x10, 0x100) self.assertRaises(ValueError, Rcode, 0x100, 0x10) diff --git a/src/lib/dns/python/tests/rrclass_python_test.py b/src/lib/dns/python/tests/rrclass_python_test.py index a195cd1908..38d8c8c34d 100644 --- a/src/lib/dns/python/tests/rrclass_python_test.py +++ b/src/lib/dns/python/tests/rrclass_python_test.py @@ -40,6 +40,8 @@ class RRClassTest(unittest.TestCase): # explicit tests for it. self.assertRaises(ValueError, RRClass, 65536) self.assertRaises(TypeError, RRClass, -1) + self.assertEqual(RRClass(65535).get_code(), 65535) + self.assertEqual(RRClass(0).get_code(), 0) def test_rrclass_to_text(self): self.assertEqual("IN", self.c1.to_text()) From c4d150ae4528f15fe8f05dbc85a1025abc92e78a Mon Sep 17 00:00:00 2001 From: chenzhengzhang Date: Fri, 8 Apr 2011 09:50:54 +0800 Subject: [PATCH 49/72] [trac363] duplicate test case cleanup --- src/lib/dns/python/tests/name_python_test.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/dns/python/tests/name_python_test.py b/src/lib/dns/python/tests/name_python_test.py index 1d8d68360f..b8e625ab2c 100644 --- a/src/lib/dns/python/tests/name_python_test.py +++ b/src/lib/dns/python/tests/name_python_test.py @@ -155,8 +155,6 @@ class NameTest(unittest.TestCase): self.assertRaises(TypeError, self.name1.split, "wrong", 1) self.assertRaises(TypeError, self.name1.split, 1, "wrong") - s = self.name1.split(0) - self.assertEqual("example.com.", s.to_text()) s = self.name1.split(1) self.assertEqual("com.", s.to_text()) From ce281e646be9f0f273229d94ccd75bf7e08d17cf Mon Sep 17 00:00:00 2001 From: chenzhengzhang Date: Fri, 8 Apr 2011 11:09:03 +0800 Subject: [PATCH 50/72] [master] merge #363 --- ChangeLog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3f0d24d6d9..0bc5627cf4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ + 217. [bug] jerry + src/lib/dns/python: Use a signed version of larger size of integer and + perform more strict range checks with PyArg_ParseTuple() in case of + overflows. + (Trac #363, git TBD) + 216. [func] vorner The BIND10_XFROUT_SOCKET_FILE environment variable can be used to specify which socket should be used for communication between b10-auth and From 2e92b2f8a977a376fa38e3a51c9646ea9e83c4b8 Mon Sep 17 00:00:00 2001 From: chenzhengzhang Date: Fri, 8 Apr 2011 11:09:45 +0800 Subject: [PATCH 51/72] [master] ChangeLog --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0bc5627cf4..c73499edbd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,7 @@ src/lib/dns/python: Use a signed version of larger size of integer and perform more strict range checks with PyArg_ParseTuple() in case of overflows. - (Trac #363, git TBD) + (Trac #363, git ce281e646be9f0f273229d94ccd75bf7e08d17cf) 216. [func] vorner The BIND10_XFROUT_SOCKET_FILE environment variable can be used to specify From a2d07257bc12397054a57d4190cc61419e572278 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Fri, 8 Apr 2011 07:49:14 +0000 Subject: [PATCH 52/72] [master] urgent care fix for build errors with sunstudio: - use instead of (e.g. use stdlib.h instead of cstdlib) - avoid using variable length array as for the first point, it didn't make sense that cxxx didn't work and we may want to look into it further to understand the real cause. but since this has been breaking build, and it somehow fixes the issue, I'll apply it for now. okayed on jabber. --- src/bin/auth/common.cc | 2 +- src/bin/sockcreator/sockcreator.cc | 2 +- src/bin/sockcreator/tests/sockcreator_tests.cc | 2 +- src/lib/dns/buffer.h | 2 +- src/lib/util/unittests/fork.cc | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bin/auth/common.cc b/src/bin/auth/common.cc index fe383e28dd..35381a1d49 100644 --- a/src/bin/auth/common.cc +++ b/src/bin/auth/common.cc @@ -14,7 +14,7 @@ #include #include -#include +#include using std::string; diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index b9da84fa01..6b50813f4f 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index f781332949..6065ffeb2b 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -256,7 +256,7 @@ TEST(run, bad_sockets) { // We need to construct the answer, but it depends on int length. size_t int_len(sizeof(int)); size_t result_len(4 + 2 * int_len); - char result[result_len]; + char result[4 + sizeof(int) * 2]; // Both errno parts should be 0 memset(result, 0, result_len); // Fill the 2 control parts diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h index 6fbbdb1e37..46a9bf4e13 100644 --- a/src/lib/dns/buffer.h +++ b/src/lib/dns/buffer.h @@ -15,7 +15,7 @@ #ifndef __BUFFER_H #define __BUFFER_H 1 -#include +#include #include #include diff --git a/src/lib/util/unittests/fork.cc b/src/lib/util/unittests/fork.cc index 1eeb2cc7a5..3414a3c187 100644 --- a/src/lib/util/unittests/fork.cc +++ b/src/lib/util/unittests/fork.cc @@ -20,10 +20,10 @@ #include #include #include -#include +#include #include -#include -#include +#include +#include using namespace isc::util::io; From ca4c3ad8a436b2c5660959d266c82b692271c158 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Fri, 8 Apr 2011 11:08:53 +0200 Subject: [PATCH 53/72] [master] Use loopback in tests Since we couldn't have :: as destination address (it seems), we use ::1, which should be possible. --- src/bin/sockcreator/tests/sockcreator_tests.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index 6065ffeb2b..73cbf48df6 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -64,7 +64,7 @@ namespace { // Just helper macros #define INADDR_SET(WHAT) do { WHAT.sin_addr.s_addr = INADDR_ANY; } while (0) -#define IN6ADDR_SET(WHAT) do { WHAT.sin6_addr = in6addr_any; } while (0) +#define IN6ADDR_SET(WHAT) do { WHAT.sin6_addr = in6addr_loopback; } while (0) // If the get_sock returned something useful, listen must work #define TCP_CHECK(UNUSED, SOCKET) do { \ EXPECT_EQ(0, listen(SOCKET, 1)); \ From d3dbda9445dcb699e48457e89b90c3be933ec2b9 Mon Sep 17 00:00:00 2001 From: "Jeremy C. Reed" Date: Fri, 8 Apr 2011 10:22:16 -0500 Subject: [PATCH 54/72] [master] make entry numbers flush left See http://bind10.isc.org/wiki/ChangeLogDetails As very briefly discussed on jabber, now making number entries flush left. I am also doing more cleanup. I have a script to check the ChangeLog and will be automating it. --- ChangeLog | 436 +++++++++++++++++++++++++++--------------------------- 1 file changed, 218 insertions(+), 218 deletions(-) diff --git a/ChangeLog b/ChangeLog index c73499edbd..b43594a18c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,30 +1,30 @@ - 217. [bug] jerry +217. [bug] jerry src/lib/dns/python: Use a signed version of larger size of integer and perform more strict range checks with PyArg_ParseTuple() in case of overflows. (Trac #363, git ce281e646be9f0f273229d94ccd75bf7e08d17cf) - 216. [func] vorner +216. [func] vorner The BIND10_XFROUT_SOCKET_FILE environment variable can be used to specify which socket should be used for communication between b10-auth and b10-xfrout. Mostly for testing reasons. (Trac #615, git 28b01ad5bf72472c824a7b8fc4a8dc394e22e462) - 215. [func] vorner +215. [func] vorner A new process, b10-sockcreator, is added, which will create sockets for the rest of the system. It is the only part which will need to keep the root privileges. However, only the process exists, nothing can talk to it yet. (Trac #366, git b509cbb77d31e388df68dfe52709d6edef93df3f) - 214. [func]* vorner +214. [func]* vorner Zone manager no longer thinks it is secondary master for all zones in the database. They are listed in Zonemgr/secondary_zones configuration variable (in the form [{"name": "example.com", "class": "IN"}]). (Trac #670, git 7c1e4d5e1e28e556b1d10a8df8d9486971a3f052) - 213. [bug] naokikambe +213. [bug] naokikambe Solved incorrect datetime of "bind10.boot_time" and also added a new command "sendstats" for Bob. This command is to send statistics data to the stats daemon immediately. The solved problem is that statistics @@ -34,83 +34,83 @@ resending statistics data via bindctl manually. (Trac #521, git 1c269cbdc76f5dc2baeb43387c4d7ccc6dc863d2) - 212. [bug] naokikambe +212. [bug] naokikambe Fixed that the ModuleCCSession object may group_unsubscribe in the closed CC session in being deleted. (Trac #698, git 0355bddc92f6df66ef50b920edd6ec3b27920d61) - 211. [func] shane +211. [func] shane Implement "--brittle" option, which causes the server to exit if any of BIND 10's processes dies. (Trac #788, git 88c0d241fe05e5ea91b10f046f307177cc2f5bc5) - 210. [bug] jerry +210. [bug] jerry src/bin/auth: fixed a bug where type ANY queries don't provide additional glue records for ANSWER section. (Trac #699, git 510924ebc57def8085cc0e5413deda990b2abeee) - 209. [func] jelte +209. [func] jelte Resolver now uses the NSAS when looking for a nameserver to query for any specific zone. This also includes keeping track of the RTT for that nameserver. (Trac #495, git 76022a7e9f3ff339f0f9f10049aa85e5784d72c5) - 208. [bug]* jelte +208. [bug]* jelte Resolver now answers REFUSED on queries that are not for class IN. This includes the various CH TXT queries, which will be added later. (git 012f9e78dc611c72ea213f9bd6743172e1a2ca20) - 207. [func] jelte +207. [func] jelte Resolver now starts listening on localhost:53 if no configuration is set. (Trac #471, git 1960b5becbba05570b9c7adf5129e64338659f07) - 206. [func] shane +206. [func] shane Add the ability to list the running BIND 10 processes using the command channel. To try this, use "Boss show_processes". (Trac #648, git 451bbb67c2b5d544db2f7deca4315165245d2b3b) - 205. [bug] jinmei +205. [bug] jinmei b10-auth, src/lib/datasrc: fixed a bug where b10-auth could return an empty additional section for delegation even if some glue is crucial when it fails to find some other glue records in its data source. (Trac #646, git 6070acd1c5b2f7a61574eda4035b93b40aab3e2b) - 204. [bug] jinmei +204. [bug] jinmei b10-auth, src/lib/datasrc: class ANY queries were not handled correctly in the generic data source (mainly for sqlite3). It could crash b10-auth in the worst case, and could result in incorrect responses in some other cases. (Trac #80, git c65637dd41c8d94399bd3e3cee965b694b633339) - 203. [bug] zhang likun +203. [bug] zhang likun Fix resolver cache memory leak: when cache is destructed, rrset and message entries in it are not destructed properly. (Trac #643, git aba4c4067da0dc63c97c6356dc3137651755ffce) - 202. [func] vorner +202. [func] vorner It is possible to specify a different directory where we look for configuration files (by -p) and different configuration file to use (-c). Also, it is possible to specify the port on which cmdctl should listen (--cmdctl-port). (Trac #615, git 5514dd78f2d61a222f3069fc94723ca33fb3200b) - 201. [bug] jerry +201. [bug] jerry src/bin/bindctl: bindctl doesn't show traceback on shutdown. (Trac #588, git 662e99ef050d98e86614c4443326568a0b5be437) - 200. [bug] Jelte +200. [bug] Jelte Fixed a bug where incoming TCP connections were not closed. (Trac #589, git 1d88daaa24e8b1ab27f28be876f40a144241e93b) - 199. [func] ocean +199. [func] ocean Cache negative responses (NXDOMAIN/NODATA) from authoritative server for recursive resolver. (Trac #493, git f8fb852bc6aef292555063590c361f01cf29e5ca) - 198. [bug] jinmei +198. [bug] jinmei b10-auth, src/lib/datasrc: fixed a bug where hot spot cache failed to reuse cached SOA for negative responses. Due to this bug b10-auth returned SERVFAIL when it was expected to return a @@ -118,42 +118,42 @@ the zone. (Trac #626, git 721a53160c15e8218f6798309befe940b9597ba0) - 197. [bug] zhang likun +197. [bug] zhang likun Remove expired message and rrset entries when looking up them in cache, touch or remove the rrset entry in cache properly when doing lookup or update. (Trac #661, git 9efbe64fe3ff22bb5fba46de409ae058f199c8a7) - 196. [bug] jinmei +196. [bug] jinmei b10-auth, src/lib/datasrc: the backend of the in-memory data source could not handle the root name. As a result b10-auth could not work as a root server when using the in-memory data source. (Trac #683, git 420ec42bd913fb83da37b26b75faae49c7957c46) - 195. [func] stephen +195. [func] stephen Resolver will now re-try a query over TCP if a response to a UDP query has the TC bit set. (Trac #499, git 4c05048ba059b79efeab53498737abe94d37ee07) - 194. [bug] vorner +194. [bug] vorner Solved a 100% CPU usage problem after switching addresses in b10-auth (and possibly, but unconfirmed, in b10-resolver). It was caused by repeated reads/accepts on closed socket (the bug was in the code for a long time, recent changes made it show). (Trac #657, git e0863720a874d75923ea66adcfbf5b2948efb10a) - 193. [func]* jreed +193. [func]* jreed Listen on the IPv6 (::) and IPv4 (0.0.0.0) wildcard addresses for b10-auth. This returns to previous behavior prior to change #184. Document the listen_on configuration in manual. (Trac #649, git 65a77d8fde64d464c75917a1ab9b6b3f02640ca6) - 192. [func]* jreed +192. [func]* jreed Listen on standard domain port 53 for b10-auth and b10-resolver. (Trac #617, #618, git 137a6934a14cf0c5b5c065e910b8b364beb0973f) - 191. [func] jinmei +191. [func] jinmei Imported system test framework of BIND 9. It can be run by 'make systest' at the top source directory. Notes: currently it doesn't work when built in a separate tree. It also requires @@ -163,51 +163,51 @@ to the specified file. (Trac #606, git 6ac000df85625f5921e8895a1aafff5e4be3ba9c) - 190. [func] jelte +190. [func] jelte Resolver now sets random qids on outgoing queries using the boost::mt19937 prng. (Trac #583, git 5222b51a047d8f2352bc9f92fd022baf1681ed81) - 189. [bug] jreed +189. [bug] jreed Do not install the log message compiler. (Trac #634, git eb6441aca464980d00e3ff827cbf4195c5a7afc5) - 188. [bug] zhang likun +188. [bug] zhang likun Make the rrset trust level ranking algorithm used by isc::cache::MessageEntry::getRRsetTrustLevel() follow RFC2181 section 5.4.1. (Trac #595 git 19197b5bc9f2955bd6a8ca48a2d04472ed696e81) - 187. [bug] zhang likun +187. [bug] zhang likun Fix the assert error in class isc::cache::RRsetCache by adding the check for empty pointer and test case for it. (Trac #638, git 54e61304131965c4a1d88c9151f8697dcbb3ce12) - 186. [bug] jelte +186. [bug] jelte b10-resolver could stop with an assertion failure on certain kinds of messages (there was a problem in error message creation). This fixes that. (Trac #607, git 25a5f4ec755bc09b54410fcdff22691283147f32) - 185. [bug] vorner +185. [bug] vorner Tests use port from private range (53210), lowering chance of a conflict with something else (eg. running bind 10). (Trac #523, git 301da7d26d41e64d87c0cf72727f3347aa61fb40) - 184. [func]* vorner +184. [func]* vorner Listening address and port configuration of b10-auth is the same as for b10-resolver now. That means, it is configured through bindctl at runtime, in the Auth/listen_on list, not through command line arguments. (Trac #575, #576, git f06ce638877acf6f8e1994962bf2dbfbab029edf) - 183. [bug] jerry +183. [bug] jerry src/bin/xfrout: Enable parallel sessions between xfrout server and muti-Auth. The session needs to be created only on the first time or if an error occur. (Trac #419, git 1d60afb59e9606f312caef352ecb2fe488c4e751) - 182. [func] jinmei +182. [func] jinmei Support cppcheck for static code check on C++ code. If cppcheck is available, 'make cppcheck' on the top source directory will run the checker and should cleanly complete with an exit code of 0 @@ -217,46 +217,46 @@ the git repository. (Trac #613, git b973f67520682b63ef38b1451d309be9f4f4b218) - 181. [func] feng +181. [func] feng Add stop interface into dns server, so we can stop each running server individually. With it, user can reconfigure her running server with different ip address or port. (Trac #388, git 6df94e2db856c1adc020f658cc77da5edc967555) - 180. [build] jreed +180. [build] jreed Fix custom DESTDIR for make install. Patch from Jan Engelhardt. (Trac #629, git 5ac67ede03892a5eacf42ce3ace1e4e376164c9f) bind10-devel-20110224 released on February 24, 2011 - 179. [func] vorner +179. [func] vorner It is possible to start and stop resolver and authoritative server without restart of the whole system. Change of the configuration (Boss/start_auth and Boss/start_resolver) is enough. (Trac #565, git 0ac0b4602fa30852b0d86cc3c0b4730deb1a58fe) - 178. [func] jelte +178. [func] jelte Resolver now makes (limited) use of the cache (Trac #491, git 8b41f77f0099ddc7ca7d34d39ad8c39bb1a8363c) - 177. [func] stephen +177. [func] stephen The upstream fetch code in asiolink is now protocol agnostic to allow for the addition of fallback to TCP if a fetch response indicates truncation. (Trac #554, git 9739cbce2eaffc7e80640db58a8513295cf684de) - 176. [func] zhang likun +176. [func] zhang likun src/lib/cache: Rename one interface: from lookupClosestRRset() to lookupDeepestNS(), and remove one parameter of it. (Trac #492, git ecbfb7cf929d62a018dd4cdc7a841add3d5a35ae) - 175. [bug] jerry +175. [bug] jerry src/bin/xfrout: Xfrout use the case-sensitive mode to compress names in an AXFR massage. (Trac #253, git 004e382616150f8a2362e94d3458b59bb2710182) - 174. [bug]* jinmei +174. [bug]* jinmei src/lib/dns: revised dnssectime functions so that they don't rely on the time_t type (whose size varies on different systems, which can lead to subtle bugs like some form of "year 2038 problem"). @@ -265,19 +265,19 @@ bind10-devel-20110224 released on February 24, 2011 should be minimal because these functions are mostly private. (Trac #61, git 09ece8cdd41c0f025e8b897b4883885d88d4ba5d) - 173. [bug] jerry +173. [bug] jerry python/isc/notify: A notify_out test fails without network connectivity, encapsulate the socket behavior using a mock socket class to fix it. (Trac #346, git 319debfb957641f311102739a15059f8453c54ce) - 172. [func] jelte +172. [func] jelte Improved the bindctl cli in various ways, mainly concerning list and map item addressing, the correct display of actual values, and internal help. (Trac #384, git e5fb3bc1ed5f3c0aec6eb40a16c63f3d0fc6a7b2) - 171. [func] feng, jerry, jinmei, vorner +171. [func] feng, jerry, jinmei, vorner b10-auth, src/lib/datasrc: in memory data source now works as a complete data source for authoritative DNS servers and b10-auth uses it. It still misses major features, however, including @@ -285,54 +285,54 @@ bind10-devel-20110224 released on February 24, 2011 (Last trac #553, but many more, git 6f031a09a248e7684723c000f3e8cc981dcdb349) - 170. [bug] jinmei +170. [bug] jinmei Tightened validity checks in the NSEC3 constructors, both "from "text" and "from wire". Specifically, wire data containing invalid type bitmaps or invalid lengths of salt or hash is now correctly rejected. (Trac #117, git 9c690982f24fef19c747a72f43c4298333a58f48) - 169. [func] zhang likun, jelte +169. [func] zhang likun, jelte Added a basic implementation for a resolver cache (though not used yet). (Trac #449, git 8aa3b2246ae095bbe7f855fd11656ae3bdb98986) - 168. [bug] vorner +168. [bug] vorner Boss no longer has the -f argument, which was undocumented and stayed as a relict of previous versions, currently causing only strange behaviour. (Trac #572, git 17f237478961005707d649a661cc72a4a0d612d4) - 167. [bug] naokikambe +167. [bug] naokikambe Fixed failure of termination of msgq_test.py with python3 coverage(3.3.1) (Trac #573, git 0e6a18e12f61cc482e07078776234f32605312e5) - 166. [func] jelte +166. [func] jelte The resolver now sends back a SERVFAIL when there is a client timeout (timeout_client config setting), but it will not stop resolving (until there is a lookup timeout or a result). (Trac #497 and #489, git af0e5cd93bebb27cb5c4457f7759d12c8bf953a6) - 165. [func] jelte +165. [func] jelte The resolver now handles CNAMEs, it will follow them, and include them in the answer. The maximum length of CNAME chains that is supported is 16. (Trac #497, git af0e5cd93bebb27cb5c4457f7759d12c8bf953a6) - 164. [bug] y-aharen +164. [bug] y-aharen IntervalTimer: Modified the interface to accept interval in milliseconds. It shortens the time of the tests of IntervalTimer. (Trac #452, git c9f6acc81e24c4b8f0eb351123dc7b43f64e0914) - 163. [func] vorner +163. [func] vorner The pimpl design pattern is used in UDPServer, with a shared pointer. This makes it smaller to copy (which is done a lot as a sideeffect of being coroutine) and speeds applications of this class (notably b10-auth) up by around 10%. (Trac #537, git 94cb95b1d508541201fc064302ba836164d3cbe6) - 162. [func] stephen +162. [func] stephen Added C++ logging, allowing logging at different severities. Code specifies the message to be logged via a symbol, and the logging code picks up the message from an in-built dictionary. @@ -341,13 +341,13 @@ bind10-devel-20110224 released on February 24, 2011 to create message header files and supply the default messages. (Trac #438, git 7b1606cea7af15dc71f5ec1d70d958b00aa98af7) - 161. [func] stephen +161. [func] stephen Added ResponseScrubber class to examine response from a server and to remove out-of-bailiwick RRsets. Also does cross-section checks to ensure consistency. (Trac #496, git b9296ca023cc9e76cda48a7eeebb0119166592c5) - 160. [func] jelte +160. [func] jelte Updated the resolver to take 3 different timeout values; timeout_query for outstanding queries we sent while resolving timeout_client for sending an answer back to the client @@ -355,14 +355,14 @@ bind10-devel-20110224 released on February 24, 2011 (currently 2 and 3 have the same final effect) (Trac #489, git 578ea7f4ba94dc0d8a3d39231dad2be118e125a2) - 159. [func] smann +159. [func] smann The resolver now has a configurable set of root servers to start resolving at (called root_addresses). By default these are not (yet) filled in. If empty, a hardcoded address for f-root will be used right now. (Trac #483, git a07e078b4feeb01949133fc88c9939254c38aa7c) - 158. [func] jelte +158. [func] jelte The Resolver module will now do (very limited) resolving, if not set to forwarding mode (i.e. if the configuration option forward_addresses is left empty). It only supports referrals that @@ -370,24 +370,24 @@ bind10-devel-20110224 released on February 24, 2011 of authoritative answers. (Trac #484, git 7b84de4c0e11f4a070e038ca4f093486e55622af) - 157. [bug] vorner +157. [bug] vorner One frozen process no longer freezes the whole b10-msgq. It caused the whole system to stop working. (Trac #420, git 93697f58e4d912fa87bc7f9a591c1febc9e0d139) - 156. [func] stephen +156. [func] stephen Added ResponseClassifier class to examine response from a server and classify it into one of several categories. (Trac #487, git 18491370576e7438c7893f8551bbb8647001be9c) bind10-devel-20110120 released on January 20, 2011 - 155. [doc] jreed +155. [doc] jreed Miscellaneous documentation improvements for man pages and the guide, including auth, resolver, stats, xfrout, and zonemgr. (git c14c4741b754a1eb226d3bdc3a7abbc4c5d727c0) - 154. [bug] jinmei +154. [bug] jinmei b10-xfrin/b10-zonemgr: Fixed a bug where these programs didn't receive command responses from CC sessions. Eventually the receive buffer became full, and many other components that rely @@ -396,12 +396,12 @@ bind10-devel-20110120 released on January 20, 2011 to revisit it for cleaner fix later. (Trac #516, git 62c72fcdf4617e4841e901408f1e7961255b8194) - 153. [bug] jelte +153. [bug] jelte b10-cfgmgr: Fixed a bug where configuration updates sometimes lost previous settings in the configuration manager. (Trac #427, git 2df894155657754151e0860e2ca9cdbed7317c70) - 152. [func]* jinmei +152. [func]* jinmei b10-auth: Added new configuration variable "statistics-interval" to allow the user to change the timer interval for periodic statistics updates. The update can also be disabled by setting @@ -410,46 +410,46 @@ bind10-devel-20110120 released on January 20, 2011 sending statistics and stop responding to queries as a result. (Trac #513, git 285c5ee3d5582ed6df02d1aa00387f92a74e3695) - 151. [bug] smann +151. [bug] smann lib/log/dummylog.h: lib/log/dummylog.cc: Modify dlog so that it takes an optional 2nd argument of type bool (true or false). This flag, if set, will cause the message to be printed whether or not -v is chosen. (trac #432, git 880220478c3e8702d56d761b1e0b21b77d08ee5a) - 150. [bug] jelte +150. [bug] jelte b10-cfgmgr: No longer save the configuration on exit. Configuration is already saved if it is changed successfully, so writing it on exit (and hence, when nothing has changed too) is unnecessary and may even cause problems. (Trac #435, git fd7baa38c08d54d5b5f84930c1684c436d2776dc) - 149. [bug] jelte +149. [bug] jelte bindctl: Check if the user session has disappeared (either by a timeout or by a server restart), and reauthenticate if so. This fixes the 'cmdctl not running' problem. (trac #431, git b929be82fec5f92e115d8985552f84b4fdd385b9) - 148. [func] jelte +148. [func] jelte bindctl: Command results are now pretty-printed (i.e. printed in a more readable form). Empty results are no longer printed at all (used to print '{}'), and the message 'send the command to cmd-ctrl' has also been removed. (git 3954c628c13ec90722a2d8816f52a380e0065bae) - 147. [bug] jinmei +147. [bug] jinmei python/isc/config: Fixed a bug that importing custom configuration (in b10-config.db) of a remote module didn't work. (Trac #478, git ea4a481003d80caf2bff8d0187790efd526d72ca) - 146. [func] jelte +146. [func] jelte Command arguments were not validated internally against their specifications. This change fixes that (on the C++ side, Python side depends on an as yet planned addition). Note: this is only an added internal check, the cli already checks format. (Trac #473, git 5474eba181cb2fdd80e2b2200e072cd0a13a4e52) - 145. [func]* jinmei +145. [func]* jinmei b10-auth: added a new command 'loadzone' for (re)loading a specific zone. The command syntax is generic but it is currently only feasible for class IN in memory data source. To reload a @@ -458,7 +458,7 @@ bind10-devel-20110120 released on January 20, 2011 (Trac #467 git 4f7e1f46da1046de527ab129a88f6aad3dba7562 from 1d7d3918661ba1c6a8b1e40d8fcbc5640a84df12) - 144. [build] jinmei +144. [build] jinmei Introduced a workaround for clang++ build on FreeBSD (and probably some other OSes). If building BIND 10 fails with clang++ due to a link error about "__dso_handle", try again from the configure @@ -469,23 +469,23 @@ bind10-devel-20110120 released on January 20, 2011 variable by hand. (Trac #474, git cfde436fbd7ddf3f49cbbd153999656e8ca2a298) - 143. [build] jinmei +143. [build] jinmei Fixed build problems with clang++ in unit tests due to recent changes. No behavior change. (Trac #448, svn r4133) - 142. [func] jinmei +142. [func] jinmei b10-auth: updated query benchmark so that it can test in memory data source. Also fixed a bug that the output buffer isn't cleared after query processing, resulting in misleading results or program crash. This is a regression due to change #135. (Trac #465, svn r4103) - 141. [bug] jinmei +141. [bug] jinmei b10-auth: Fixed a bug that the authoritative server includes trailing garbage data in responses. This is a regression due to change #135. (Trac #462, svn r4081) - 140. [func] y-aharen +140. [func] y-aharen src/bin/auth: Added a feature to count queries and send counter values to statistics periodically. To support it, added wrapping class of asio::deadline_timer to use as interval timer. @@ -496,14 +496,14 @@ bind10-devel-20110120 released on January 20, 2011 counters to b10-stats immediately. (Trac #347, svn r4026) - 139. [build] jreed +139. [build] jreed Introduced configure option and make targets for generating Python code coverage report. This adds new make targets: report-python-coverage and clean-python-coverage. The C++ code coverage targets were renamed to clean-cpp-coverage and report-cpp-coverage. (Trac #362, svn r4023) - 138. [func]* jinmei +138. [func]* jinmei b10-auth: added a configuration interface to support in memory data sources. For example, the following command to bindctl will configure a memory data source containing the "example.com" @@ -520,45 +520,45 @@ bind10-devel-20110120 released on January 20, 2011 future versions. (Trac #446, svn r3998) - 137. [bug] jreed +137. [bug] jreed Fix run_*.sh scripts that are used for development testing so they use a msgq socket file in the build tree. (Trac #226, svn r3989) - 136. [bug] jelte +136. [bug] jelte bindctl (and the configuration manager in general) now no longer accepts 'unknown' data; i.e. data for modules that it does not know about, or configuration items that are not specified in the .spec files. (Trac #202, svn r3967) - 135. [func] each +135. [func] each Add b10-resolver. This is an example recursive server that currently does forwarding only and no caching. (Trac #327, svn r3903) - 134. [func] vorner +134. [func] vorner b10-resolver supports timeouts and retries in forwarder mode. (Trac #401, svn r3660) - 133. [func] vorner +133. [func] vorner New temporary logging function available in isc::log. It is used by b10-resolver. (Trac #393, r3602) - 132. [func] vorner +132. [func] vorner The b10-resolver is configured through config manager. It has "listen_on" and "forward_addresses" options. (Trac #389, r3448) - 131. [func] feng, jerry +131. [func] feng, jerry src/lib/datasrc: Introduced two template classes RBTree and RBNode to provide the generic map with domain name as key and anything as the value. Because of some unresolved design issue, the new classes are only intended to be used by memory zone and zone table. (Trac #397, svn r3890) - 130. [func] jerry +130. [func] jerry src/lib/datasrc: Introduced a new class MemoryDataSrc to provide the general interface for memory data source. For the initial implementation, we don't make it a derived class of AbstractDataSrc @@ -566,24 +566,24 @@ bind10-devel-20110120 released on January 20, 2011 as part of the generalization work). (Trac #422, svn r3866) - 129. [func] jinmei +129. [func] jinmei src/lib/dns: Added new functions masterLoad() for loading master zone files. The initial implementation can only parse a limited form of master files, but BIND 9's named-compilezone can convert any valid zone file into the acceptable form. (Trac #423, svn r3857) - 128. [build] vorner +128. [build] vorner Test for query name = '.', type = DS to authoritative nameserver for root zone was added. (Trac #85, svn r3836) - 127. [bug] stephen +127. [bug] stephen During normal operation process termination and resurrection messages are now output regardless of the state of the verbose flag. (Trac #229, svn r3828) - 126. [func] stephen, vorner, ocean +126. [func] stephen, vorner, ocean The Nameserver Address Store (NSAS) component has been added. It takes care of choosing an IP address of a nameserver when a zone needs to be contacted. @@ -591,38 +591,38 @@ bind10-devel-20110120 released on January 20, 2011 bind10-devel-20101201 released on December 01, 2010 - 125. [func] jelte +125. [func] jelte Added support for addressing individual list items in bindctl configuration commands; If you have an element that is a list, you can use foo[X] to address a specific item, where X is an integer (starting at 0) (Trac #405, svn r3739) - 124. [bug] jreed +124. [bug] jreed Fix some wrong version reporting. Now also show the version for the component and BIND 10 suite. (Trac #302, svn r3696) - 123. [bug] jelte +123. [bug] jelte src/bin/bindctl printed values had the form of python literals (e.g. 'True'), while the input requires valid JSON (e.g. 'true'). Output changed to JSON format for consistency. (svn r3694) - 122. [func] stephen +122. [func] stephen src/bin/bind10: Added configuration options to Boss to determine whether to start the authoritative server, recursive server (or both). A dummy program has been provided for test purposes. (Trac #412, svn r3676) - 121. [func] jinmei +121. [func] jinmei src/lib/dns: Added support for TSIG RDATA. At this moment this is not much of real use, however, because no protocol support was added yet. It will soon be added. (Trac #372, svn r3649) - 120. [func] jinmei +120. [func] jinmei src/lib/dns: introduced two new classes, TSIGKey and TSIGKeyRing, to manage TSIG keys. (Trac #381, svn r3622) - 119. [bug] jinmei +119. [bug] jinmei The master file parser of the python datasrc module incorrectly regarded a domain name beginning with a decimal number as a TTL specification. This confused b10-loadzone and had it reject to @@ -632,158 +632,158 @@ bind10-devel-20101201 released on December 01, 2010 from a TTL specification. This is part of a more general issue and will be addressed in Trac #413. (Trac #411, svn r3599) - 118. [func] jinmei +118. [func] jinmei src/lib/dns: changed the interface of AbstractRRset::getRdataIterator() so that the internal cursor would point to the first RDATA automatically. This will be a more intuitive and less error prone behavior. This is a backward compatible change. (Trac #410, r3595) - 117. [func] jinmei +117. [func] jinmei src/lib/datasrc: added new zone and zone table classes for the support of in memory data source. This is an intermediate step to the bigger feature, and is not yet actually usable in practice. (Trac #399, svn r3590) - 116. [bug] jerry +116. [bug] jerry src/bin/xfrout: Xfrout and Auth will communicate by long tcp connection, Auth needs to make a new connection only on the first time or if an error occurred. (Trac #299, svn r3482) - 115. [func]* jinmei +115. [func]* jinmei src/lib/dns: Changed DNS message flags and section names from separate classes to simpler enums, considering the balance between type safety and usability. API has been changed accordingly. More documentation and tests were provided with these changes. (Trac #358, r3439) - 114. [build] jinmei +114. [build] jinmei Supported clang++. Note: Boost >= 1.44 is required. (Trac #365, svn r3383) - 113. [func]* zhanglikun +113. [func]* zhanglikun Folder name 'utils'(the folder in /src/lib/python/isc/) has been renamed to 'util'. Programs that used 'import isc.utils.process' now need to use 'import isc.util.process'. The folder /src/lib/python/isc/Util is removed since it isn't used by any program. (Trac #364, r3382) - 112. [func] zhang likun +112. [func] zhang likun Add one mixin class to override the naive serve_forever() provided in python library socketserver. Instead of polling for shutdown every poll_interval seconds, one socketpair is used to wake up the waiting server. (Trac #352, svn r3366) - 111. [bug]* zhanglikun, Michal Vaner +111. [bug]* zhanglikun, Michal Vaner Make sure process xfrin/xfrout/zonemgr/cmdctl can be stopped properly when user enter "ctrl+c" or 'Boss shutdown' command through bindctl. The ZonemgrRefresh.run_timer and NotifyOut.dispatcher spawn a thread themselves. (Trac #335, svn r3273) - 110. [func] Michal Vaner +110. [func] Michal Vaner Added isc.net.check module to check ip addresses and ports for correctness and isc.net.addr to hold IP address. The bind10, xfrin and cmdctl programs are modified to use it. (Trac #353, svn r3240) - 109. [func] naokikambe +109. [func] naokikambe Added the initial version of the stats module for the statistics feature of BIND 10, which supports the restricted features and items and reports via bindctl command. (Trac #191, r3218) Added the document of the stats module, which is about how stats module collects the data (Trac #170, [wiki:StatsModule]) - 108. [func] jerry +108. [func] jerry src/bin/zonemgr: Provide customizable configurations for lowerbound_refresh, lowerbound_retry, max_transfer_timeout and jitter_scope. (Trac #340, r3205) - 107. [func] zhang likun +107. [func] zhang likun Remove the parameter 'db_file' for command 'retransfer' of xfrin module. xfrin.spec will not be generated by script. (Trac #329, r3171) - 106. [bug] zhang likun +106. [bug] zhang likun When xfrin can't connect with one zone's master, it should tell the bad news to zonemgr, so that zonemgr can reset the timer for that zone. (Trac #329, r3170) - 105. [bug] Michal Vaner +105. [bug] Michal Vaner Python processes: they no longer take 100% CPU while idle due to a busy loop in reading command session in a nonblocking way. (Trac #349, svn r3153), (Trac #382, svn r3294) - 104. [bug] jerry +104. [bug] jerry bin/zonemgr: zonemgr should be attempting to refresh expired zones. (Trac #336, r3139) - 103. [bug] jerry +103. [bug] jerry lib/python/isc/log: Fixed an issue with python logging, python log shouldn't die with OSError. (Trac #267, r3137) - 102. [build] jinmei +102. [build] jinmei Disable threads in ASIO to minimize build time dependency. (Trac #345, r3100) - 101. [func] jinmei +101. [func] jinmei src/lib/dns: Completed Opcode and Rcode implementation with more tests and documentation. API is mostly the same but the validation was a bit tightened. (Trac #351, svn r3056) - 100. [func] Michal Vaner +100. [func] Michal Vaner Python processes: support naming of python processes so they're not all called python3. (Trac #322, svn r3052) - 99. [func]* jinmei +99. [func]* jinmei Introduced a separate EDNS class to encapsulate EDNS related information more cleanly. The related APIs are changed a bit, although it won't affect most of higher level applications. (Trac #311, svn r3020) - 98. [build] jinmei +98. [build] jinmei The ./configure script now tries to search some common include paths for boost header files to minimize the need for explicit configuration with --with-boost-include. (Trac #323, svn r3006) - 97. [func] jinmei +97. [func] jinmei Added a micro benchmark test for query processing of b10-auth. (Trac #308, svn r2982) - 96. [bug] jinmei +96. [bug] jinmei Fixed two small issues with configure: Do not set CXXFLAGS so that it can be customized; Make sure --disable-static works. (Trac #325, r2976) bind10-devel-20100917 released on September 17, 2010 - 95. [doc] jreed +95. [doc] jreed Add b10-zonemgr manual page. Update other docs to introduce this secondary manager. (Trac #341, svn r2951) - 95. [bug] jreed +95. [bug] jreed bin/xfrout and bin/zonemgr: Fixed some stderr output. (Trac #342, svn r2949) - 94. [bug] jelte +94. [bug] jelte bin/xfrout: Fixed a problem in xfrout where only 2 or 3 RRs were used per DNS message in the xfrout stream. (Trac #334, r2931) - 93. [bug] jinmei +93. [bug] jinmei lib/datasrc: A DS query could crash the library (and therefore, e.g. the authoritative server) if some RR of the same apex name is stored in the hot spot cache. (Trac #307, svn r2923) - 92. [func]* jelte +92. [func]* jelte libdns_python (the python wrappers for libdns++) has been renamed to pydnspp (Python DNS++). Programs and libraries that used 'import libdns_python' now need to use 'import pydnspp'. (Trac #314, r2902) - 91. [func]* jinmei +91. [func]* jinmei lib/cc: Use const pointers and const member functions for the API as much as possible for safer operations. Basically this does not change the observable behavior, but some of the API were changed @@ -791,36 +791,36 @@ bind10-devel-20100917 released on September 17, 2010 copies, but at this moment the overhead is deemed acceptable. (Trac #310, r2803) - 90. [build] jinmei +90. [build] jinmei (Darwin/Mac OS X specific) Specify DYLD_LIBRARY_PATH for tests and experimental run under the source tree. Without this loadable python modules refer to installation paths, which may confuse the operation due to version mismatch or even trigger run time errors due to missing libraries. (Trac #313, r2782) - 89. [build] jinmei +89. [build] jinmei Generate b10-config.db for tests at build time so that the source tree does not have to be writable. (Trac #315, r2776) - 88. [func] jelte +88. [func] jelte Blocking reads on the msgq command channel now have a timeout (defaults to 4 seconds, modifiable as needed by modules). Because of this, modules will no longer block indefinitely if they are waiting for a message that is not sent for whatever reason. (Trac #296, r2761) - 87. [func] zhanglikun +87. [func] zhanglikun lib/python/isc/notifyout: Add the feature of notify-out, when zone axfr/ixfr finishing, the server will notify its slaves. (Trac #289, svn r2737) - 86. [func] jerry +86. [func] jerry bin/zonemgr: Added zone manager module. The zone manager is one of the co-operating processes of BIND10, which keeps track of timers and other information necessary for BIND10 to act as a slave. (Trac #215, svn r2737) - 85. [build]* jinmei +85. [build]* jinmei Build programs using dynamic link by default. A new configure option --enable-static-link is provided to force static link for executable programs. Statically linked programs can be run on a @@ -829,34 +829,34 @@ bind10-devel-20100917 released on September 17, 2010 bind10-devel-20100812 released on August 12, 2010 - 84. [bug] jinmei, jerry +84. [bug] jinmei, jerry This is a quick fix patch for the issue: AXFR fails half the time because of connection problems. xfrout client will make a new connection every time. (Trac #299, svn r2697) - 83. [build]* jreed +83. [build]* jreed The configure --with-boost-lib option is removed. It was not used since the build included ASIO. (svn r2684) - 82. [func] jinmei +82. [func] jinmei bin/auth: Added -u option to change the effective process user of the authoritative server after invocation. The same option to the boss process will be propagated to b10-auth, too. (Trac #268, svn r2675) - 81. [func] jinmei +81. [func] jinmei Added a C++ framework for micro benchmark tests. A supplemental library functions to build query data for the tests were also provided. (Trac #241, svn r2664) - 80. [bug] jelte +80. [bug] jelte bindctl no longer accepts configuration changes for unknown or non-running modules (for the latter, this is until we have a way to verify those options, at which point it'll be allowed again). (Trac #99, r2657) - 79. [func] feng, jinmei +79. [func] feng, jinmei Refactored the ASIO link interfaces to move incoming XFR and NOTIFY processing to the auth server class. Wrapper classes for ASIO specific concepts were also provided, so that other BIND 10 @@ -868,7 +868,7 @@ bind10-devel-20100812 released on August 12, 2010 Note: Right now, NOTIFY doesn't actually trigger subsequent zone transfer due to security reasons. (Trac #221, r2565) - 78. [bug] jinmei +78. [bug] jinmei lib/dns: Fixed miscellaneous bugs in the base32 (hex) and hex (base16) implementation, including incorrect padding handling, parser failure in decoding with a SunStudio build, missing @@ -879,44 +879,44 @@ bind10-devel-20100812 released on August 12, 2010 libdns++, so we don't consider it a backward incompatible change. (Trac #256, r2549) - 77. [func] zhanglikun +77. [func] zhanglikun Make error message be more friendly when running cmdctl and it's already running(listening on same port)(Trac #277, r2540) - 76. [bug] jelte +76. [bug] jelte Fixed a bug in the handling of 'remote' config modules (i.e. modules that peek at the configuration of other modules), where they answered 'unknown command' to commands for those other modules. (Trac #278, r2506) - 75. [bug] jinmei +75. [bug] jinmei Fixed a bug in the sqlite3 data source where temporary strings could be referenced after destruction. It caused various lookup failures with SunStudio build. (Trac #288, r2494) - 74. [func]* jinmei +74. [func]* jinmei Refactored the cc::Session class by introducing an abstract base class. Test code can use their own derived mock class so that tests can be done without establishing a real CC session. This change also modified some public APIs, mainly in the config module. (Trac #275, r2459) - 73. [bug] jelte +73. [bug] jelte Fixed a bug where in bindctl, locally changed settings were reset when the list of running modules is updated. (Trac #285, r2452) - 72. [build] jinmei +72. [build] jinmei Added -R when linking python wrapper modules to libpython when possible. This helps build BIND 10 on platforms that install libpython whose path is unknown to run-time loader. NetBSD is a known such platform. (Trac #148, r2427) - 71. [func] each +71. [func] each Add "-a" (address) option to bind10 to specify an address for the auth server to listen on. - 70. [func] each +70. [func] each Added a hot-spot cache to libdatasrc to speed up access to repeatedly-queried data and reduce the number of queries to the underlying database; this should substantially improve @@ -926,14 +926,14 @@ bind10-devel-20100812 released on August 12, 2010 bind10-devel-20100701 released on July 1, 2010 - 69. [func]* jelte +69. [func]* jelte Added python wrappers for libdns++ (isc::dns), and libxfr. This removes the dependency on Boost.Python. The wrappers don't completely implement all functionality, but the high-level API is wrapped, and current modules use it now. (Trac #181, svn r2361) - 68. [func] zhanglikun +68. [func] zhanglikun Add options -c(--certificate-chain) to bindctl. Override class HTTPSConnection to support server certificate validation. Add support to cmdctl.spec file, now there are three configurable @@ -941,7 +941,7 @@ bind10-devel-20100701 released on July 1, 2010 all of them can be changed in runtime. (Trac #127, svn r2357) - 67. [func] zhanglikun +67. [func] zhanglikun Make bindctl's command parser only do minimal check. Parameter value can be a sequence of non-space characters, or a string surrounded by quotation marks (these marks can @@ -952,13 +952,13 @@ bind10-devel-20100701 released on July 1, 2010 avoid using Exception to catch all exceptions. (Trac #220, svn r2356) - 66. [bug] each +66. [bug] each Check for duplicate RRsets before inserting data into a message section; this, among other things, will prevent multiple copies of the same CNAME from showing up when there's a loop. (Trac #69, svn r2350) - 65. [func] shentingting +65. [func] shentingting Various loadzone improvements: allow optional comment for $TTL, allow optional origin and comment for $INCLUDE, allow optional comment for $ORIGIN, support BIND9 extension of @@ -969,71 +969,71 @@ bind10-devel-20100701 released on July 1, 2010 formats to load. (Trac #197, #199, #244, #161, #198, #174, #175, svn r2340) - 64. [func] jerry +64. [func] jerry Added python logging framework. It is for testing and experimenting with logging ideas. Currently, it supports three channels (file, syslog and stderr) and five levels (debug, info, warning, error and critical). (Trac #176, svn r2338) - 63. [func] shane +63. [func] shane Added initial support for setuid(), using the "-u" flag. This will be replaced in the future, but for now provides a reasonable starting point. (Trac #180, svn r2330) - 62. [func] jelte +62. [func] jelte bin/xfrin: Use the database_file as configured in Auth to transfers bin/xfrout: Use the database_file as configured in Auth to transfers - 61. [bug] jelte +61. [bug] jelte bin/auth: Enable b10-auth to be launched in source tree (i.e. use a zone database file relative to that) - 60. [build] jinmei +60. [build] jinmei Supported SunStudio C++ compiler. Note: gtest still doesn't work. (Trac #251, svn r2310) - 59. [bug] jinmei +59. [bug] jinmei lib/datasrc,bin/auth: The authoritative server could return a SERVFAIL with a partial answer if it finds a data source broken while looking for an answer. This can happen, for example, if a zone that doesn't have an NS RR is configured and loaded as a sqlite3 data source. (Trac #249, r2286) - 58. [bug] jinmei +58. [bug] jinmei Worked around an interaction issue between ASIO and standard C++ library headers. Without this ASIO didn't work: sometimes the application crashes, sometimes it blocked in the ASIO module. (Trac #248, svn r2187, r2190) - 57. [func] jinmei +57. [func] jinmei lib/datasrc: used a simpler version of Name::split (change 31) for better readability. No behavior change. (Trac #200, svn r2159) - 56. [func]* jinmei +56. [func]* jinmei lib/dns: renamed the library name to libdns++ to avoid confusion with the same name of library of BIND 9. (Trac #190, svn r2153) - 55. [bug] shane +55. [bug] shane bin/xfrout: xfrout exception on Ctrl-C now no longer generates exception for 'Interrupted system call' (Track #136, svn r2147) - 54. [bug] zhanglikun +54. [bug] zhanglikun bin/xfrout: Enable b10-xfrout can be launched in source code tree. (Trac #224, svn r2103) - 53. [bug] zhanglikun +53. [bug] zhanglikun bin/bindctl: Generate a unique session ID by using socket.gethostname() instead of socket.gethostbyname(), since the latter one could make bindctl stall if its own host name can't be resolved. (Trac #228, svn r2096) - 52. [func] zhanglikun +52. [func] zhanglikun bin/xfrout: When xfrout is launched, check whether the socket file is being used by one running xfrout process, if it is, exit from python. If the file isn't a socket file @@ -1043,210 +1043,210 @@ bind10-devel-20100701 released on July 1, 2010 bind10-devel-20100602 released on June 2, 2010 - 51. [build] jelte +51. [build] jelte lib/python: Add bind10_config.py module for paths and possibly other configure-time variables. Allow some components to find spec files in build tree when ran from source. (Trac #223) - 50. [bug] zhanglikun +50. [bug] zhanglikun bin/xfrin: a regression in xfrin: it can't communicate with a remote server. (Trac #218, svn r2038) - 49. [func]* jelte +49. [func]* jelte Use unix domain sockets for msgq. For b10-msgq, the command line options --msgq-port and -m were removed. For bind10, the -msgq-port option was removed, and the -m command line option was changed to be a filename (instead of port number). (Trac #183, svn r2009) - 48. [func] jelte +48. [func] jelte bin/auth: Use asio's io_service for the msgq handling. (svn r2007) - 47. [func] zhanglikun +47. [func] zhanglikun bin/cmdctl: Add value/type check for commands sent to cmdctl. (Trac #201, svn r1959) - 46. [func] zhanglikun +46. [func] zhanglikun lib/cc: Fix real type data encoding/decoding. (Trac #193, svn r1959) - 45. [func] zhanglikun +45. [func] zhanglikun bin/bind10: Pass verbose option to more modules. (Trac #205, svn r1957) - 44. [build] jreed +44. [build] jreed Install headers for libdns and libexception. (Trac #68, svn r1941) - 43. [func] jelte +43. [func] jelte lib/cc: Message queuing on cc channel. (Trac #58, svn r1870) - 42. [func] jelte +42. [func] jelte lib/python/isc/config: Make temporary file with python tempfile module instead of manual with fixed name. (Trac #184, svn r1859) - 41. [func] jelte +41. [func] jelte Module descriptions in spec files. (Trac #90, svn r1856) - 40. [build] jreed +40. [build] jreed Report detected features and configure settings at end of configure output. (svn r1836) - 39. [func]* each +39. [func]* each Renamed libauth to libdatasrc. - 38. [bug] zhanglikun +38. [bug] zhanglikun Send command 'shutdown' to Xfrin and Xfrout when boss receive SIGINT. Remove unused socket file when Xfrout process exits. Make sure Xfrout exit by itself when it receives SIGINT, instead of being killed by the signal SIGTERM or SIGKILL sent from boss. (Trac #135, #151, #134, svn r1797) - 37. [build] jinmei +37. [build] jinmei Check for the availability of python-config. (Trac #159, svn r1794) - 36. [func] shane +36. [func] shane bin/bind10: Miscellaneous code cleanups and improvements. (Trac #40, svn r2012) - 35. [bug] jinmei +35. [bug] jinmei bin/bindctl: fixed a bug that it didn't accept IPv6 addresses as command arguments. (Trac #219, svn r2022) - 34. [bug] jinmei +34. [bug] jinmei bin/xfrin: fixed several small bugs with many additional unit tests. Fixes include: IPv6 transport support, resource leak, and non IN class support. (Trac #185, svn r2000) - 33. [bug] each +33. [bug] each bin/auth: output now prepended with "[b10-auth]" (Trac #109, svn r1985) - 32. [func]* each +32. [func]* each bin/auth: removed custom query-processing code, changed boost::asio code to use plain asio instead, and added asio headers to the source tree. This allows building without using an external boost library. (Trac #163, svn r1983) - 31. [func] jinmei +31. [func] jinmei lib/dns: added a separate signature for Name::split() as a convenient wrapper for common usage. (Trac #49, svn r1903) - 30. [bug] jinmei +30. [bug] jinmei lib/dns: parameter validation of Name::split() was not sufficient, and invalid parameters could cause integer overflow and make the library crash. (Trac #177, svn r1806) bind10-devel-20100421 released on April 21, 2010 - 29. [build] +29. [build] Enable Python unit tests for "make check". (svn r1762) - 28. [bug] +28. [bug] Fix msgq CC test so it can find its module. (svn r1751) - 27. [build] +27. [build] Add missing copyright license statements to various source files. (svn r1750) - 26. [func] +26. [func] Use PACKAGE_STRING (name + version) from config.h instead of hard-coded value in CH TXT version.bind replies (Trac #114, svn r1749) - 25. [func]* +25. [func]* Renamed msgq to b10-msgq. (Trac #25, svn r1747, r1748) - 24. [func] +24. [func] Support case-sensitive name compression in MessageRenderer. (Trac #142, svn r1704) - 23. [func] +23. [func] Support a simple name with possible compression. (svn r1701) - 22. [func] +22. [func] b10-xfrout for AXFR-out support added. (svn r1629, r1630) - 21. [bug] +21. [bug] Make log message more readable when xfrin failed. (svn r1697) - 20. [bug] +20. [bug] Keep stderr for child processes if -v is specified. (svn r1690, r1698) - 19. [bug] +19. [bug] Allow bind10 boss to pass environment variables from parent. (svn r1689) - 18. [bug] +18. [bug] Xfrin warn if bind10_dns load failed. (svn r1688) - 17. [bug] +17. [bug] Use sqlite3_ds.load() in xfrin module and catch Sqlite3DSError explicitly. (svn r1684) - 16. [func]* +16. [func]* Removed print_message and print_settings configuration commands from Xfrin. (Trac #136, svn r1682) - 15. [func]* +15. [func]* Changed zone loader/updater so trailing dot is not required. (svn r1681) - 14. [bug] +14. [bug] Change shutdown to actually SIGKILL properly. (svn r1675) - 13. [bug] +13. [bug] Don't ignore other RRs than SOA even if the second SOA is found. (svn r1674) - 12. [build] +12. [build] Fix tests and testdata so can be used from a read-only source directory. - 11. [build] +11. [build] Make sure python tests scripts are included in tarball. (svn r1648) - 10. [build] +10. [build] Improve python detection for configure. (svn r1622) - 9. [build] +9. [build] Automake the python binding of libdns. (svn r1617) - 8. [bug] +8. [bug] Fix log errors which may cause xfrin module to crash. (svn r1613) - 7. [func] +7. [func] New API for inserting zone data to sqlite3 database for AXFR-in. (svn r1612, r1613) - 6. [bug] +6. [bug] More code review, miscellaneous cleanups, style guidelines, and new and improved unit tests added. - 5. [doc] +5. [doc] Manual page cleanups and improvements. - 4. [bug] +4. [bug] NSEC RDATA fixes for buffer overrun lookups, incorrect boundary checks, spec-non-conformant behaviors. (svn r1611) - 3. [bug] +3. [bug] Remove a re-raise of an exception that should only have been included in an error answer on the cc channel. (svn r1601) - 2. [bug] +2. [bug] Removed unnecessary sleep() from ccsession.cc. (svn r1528) - 1. [build]* +1. [build]* The configure --with-boostlib option changed to --with-boost-lib. bind10-devel-20100319 released on March 19, 2010 From 6555863f88c4e9865baebe0b55db1f7b00b6214c Mon Sep 17 00:00:00 2001 From: "Jeremy C. Reed" Date: Fri, 8 Apr 2011 10:50:08 -0500 Subject: [PATCH 55/72] [master] tab before entry description type and two tabs after (before name) --- ChangeLog | 192 +++++++++++++++++++++++++++--------------------------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/ChangeLog b/ChangeLog index b43594a18c..a4bb8be97c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,27 +4,27 @@ overflows. (Trac #363, git ce281e646be9f0f273229d94ccd75bf7e08d17cf) -216. [func] vorner +216. [func] vorner The BIND10_XFROUT_SOCKET_FILE environment variable can be used to specify which socket should be used for communication between b10-auth and b10-xfrout. Mostly for testing reasons. (Trac #615, git 28b01ad5bf72472c824a7b8fc4a8dc394e22e462) -215. [func] vorner +215. [func] vorner A new process, b10-sockcreator, is added, which will create sockets for the rest of the system. It is the only part which will need to keep the root privileges. However, only the process exists, nothing can talk to it yet. (Trac #366, git b509cbb77d31e388df68dfe52709d6edef93df3f) -214. [func]* vorner +214. [func]* vorner Zone manager no longer thinks it is secondary master for all zones in the database. They are listed in Zonemgr/secondary_zones configuration variable (in the form [{"name": "example.com", "class": "IN"}]). (Trac #670, git 7c1e4d5e1e28e556b1d10a8df8d9486971a3f052) -213. [bug] naokikambe +213. [bug] naokikambe Solved incorrect datetime of "bind10.boot_time" and also added a new command "sendstats" for Bob. This command is to send statistics data to the stats daemon immediately. The solved problem is that statistics @@ -34,39 +34,39 @@ resending statistics data via bindctl manually. (Trac #521, git 1c269cbdc76f5dc2baeb43387c4d7ccc6dc863d2) -212. [bug] naokikambe +212. [bug] naokikambe Fixed that the ModuleCCSession object may group_unsubscribe in the closed CC session in being deleted. (Trac #698, git 0355bddc92f6df66ef50b920edd6ec3b27920d61) -211. [func] shane +211. [func] shane Implement "--brittle" option, which causes the server to exit if any of BIND 10's processes dies. (Trac #788, git 88c0d241fe05e5ea91b10f046f307177cc2f5bc5) -210. [bug] jerry +210. [bug] jerry src/bin/auth: fixed a bug where type ANY queries don't provide additional glue records for ANSWER section. (Trac #699, git 510924ebc57def8085cc0e5413deda990b2abeee) -209. [func] jelte +209. [func] jelte Resolver now uses the NSAS when looking for a nameserver to query for any specific zone. This also includes keeping track of the RTT for that nameserver. (Trac #495, git 76022a7e9f3ff339f0f9f10049aa85e5784d72c5) -208. [bug]* jelte +208. [bug]* jelte Resolver now answers REFUSED on queries that are not for class IN. This includes the various CH TXT queries, which will be added later. (git 012f9e78dc611c72ea213f9bd6743172e1a2ca20) -207. [func] jelte +207. [func] jelte Resolver now starts listening on localhost:53 if no configuration is set. (Trac #471, git 1960b5becbba05570b9c7adf5129e64338659f07) -206. [func] shane +206. [func] shane Add the ability to list the running BIND 10 processes using the command channel. To try this, use "Boss show_processes". (Trac #648, git 451bbb67c2b5d544db2f7deca4315165245d2b3b) @@ -85,27 +85,27 @@ incorrect responses in some other cases. (Trac #80, git c65637dd41c8d94399bd3e3cee965b694b633339) -203. [bug] zhang likun +203. [bug] zhang likun Fix resolver cache memory leak: when cache is destructed, rrset and message entries in it are not destructed properly. (Trac #643, git aba4c4067da0dc63c97c6356dc3137651755ffce) -202. [func] vorner +202. [func] vorner It is possible to specify a different directory where we look for configuration files (by -p) and different configuration file to use (-c). Also, it is possible to specify the port on which cmdctl should listen (--cmdctl-port). (Trac #615, git 5514dd78f2d61a222f3069fc94723ca33fb3200b) -201. [bug] jerry +201. [bug] jerry src/bin/bindctl: bindctl doesn't show traceback on shutdown. (Trac #588, git 662e99ef050d98e86614c4443326568a0b5be437) -200. [bug] Jelte +200. [bug] Jelte Fixed a bug where incoming TCP connections were not closed. (Trac #589, git 1d88daaa24e8b1ab27f28be876f40a144241e93b) -199. [func] ocean +199. [func] ocean Cache negative responses (NXDOMAIN/NODATA) from authoritative server for recursive resolver. (Trac #493, git f8fb852bc6aef292555063590c361f01cf29e5ca) @@ -118,7 +118,7 @@ the zone. (Trac #626, git 721a53160c15e8218f6798309befe940b9597ba0) -197. [bug] zhang likun +197. [bug] zhang likun Remove expired message and rrset entries when looking up them in cache, touch or remove the rrset entry in cache properly when doing lookup or update. @@ -130,12 +130,12 @@ not work as a root server when using the in-memory data source. (Trac #683, git 420ec42bd913fb83da37b26b75faae49c7957c46) -195. [func] stephen +195. [func] stephen Resolver will now re-try a query over TCP if a response to a UDP query has the TC bit set. (Trac #499, git 4c05048ba059b79efeab53498737abe94d37ee07) -194. [bug] vorner +194. [bug] vorner Solved a 100% CPU usage problem after switching addresses in b10-auth (and possibly, but unconfirmed, in b10-resolver). It was caused by repeated reads/accepts on closed socket (the bug was in the code for a @@ -172,36 +172,36 @@ Do not install the log message compiler. (Trac #634, git eb6441aca464980d00e3ff827cbf4195c5a7afc5) -188. [bug] zhang likun +188. [bug] zhang likun Make the rrset trust level ranking algorithm used by isc::cache::MessageEntry::getRRsetTrustLevel() follow RFC2181 section 5.4.1. (Trac #595 git 19197b5bc9f2955bd6a8ca48a2d04472ed696e81) -187. [bug] zhang likun +187. [bug] zhang likun Fix the assert error in class isc::cache::RRsetCache by adding the check for empty pointer and test case for it. (Trac #638, git 54e61304131965c4a1d88c9151f8697dcbb3ce12) -186. [bug] jelte +186. [bug] jelte b10-resolver could stop with an assertion failure on certain kinds of messages (there was a problem in error message creation). This fixes that. (Trac #607, git 25a5f4ec755bc09b54410fcdff22691283147f32) -185. [bug] vorner +185. [bug] vorner Tests use port from private range (53210), lowering chance of a conflict with something else (eg. running bind 10). (Trac #523, git 301da7d26d41e64d87c0cf72727f3347aa61fb40) -184. [func]* vorner +184. [func]* vorner Listening address and port configuration of b10-auth is the same as for b10-resolver now. That means, it is configured through bindctl at runtime, in the Auth/listen_on list, not through command line arguments. (Trac #575, #576, git f06ce638877acf6f8e1994962bf2dbfbab029edf) -183. [bug] jerry +183. [bug] jerry src/bin/xfrout: Enable parallel sessions between xfrout server and muti-Auth. The session needs to be created only on the first time or if an error occur. @@ -217,36 +217,36 @@ the git repository. (Trac #613, git b973f67520682b63ef38b1451d309be9f4f4b218) -181. [func] feng +181. [func] feng Add stop interface into dns server, so we can stop each running server individually. With it, user can reconfigure her running server with different ip address or port. (Trac #388, git 6df94e2db856c1adc020f658cc77da5edc967555) -180. [build] jreed +180. [build] jreed Fix custom DESTDIR for make install. Patch from Jan Engelhardt. (Trac #629, git 5ac67ede03892a5eacf42ce3ace1e4e376164c9f) bind10-devel-20110224 released on February 24, 2011 -179. [func] vorner +179. [func] vorner It is possible to start and stop resolver and authoritative server without restart of the whole system. Change of the configuration (Boss/start_auth and Boss/start_resolver) is enough. (Trac #565, git 0ac0b4602fa30852b0d86cc3c0b4730deb1a58fe) -178. [func] jelte +178. [func] jelte Resolver now makes (limited) use of the cache (Trac #491, git 8b41f77f0099ddc7ca7d34d39ad8c39bb1a8363c) -177. [func] stephen +177. [func] stephen The upstream fetch code in asiolink is now protocol agnostic to allow for the addition of fallback to TCP if a fetch response indicates truncation. (Trac #554, git 9739cbce2eaffc7e80640db58a8513295cf684de) -176. [func] zhang likun +176. [func] likun src/lib/cache: Rename one interface: from lookupClosestRRset() to lookupDeepestNS(), and remove one parameter of it. (Trac #492, git ecbfb7cf929d62a018dd4cdc7a841add3d5a35ae) @@ -271,13 +271,13 @@ bind10-devel-20110224 released on February 24, 2011 socket class to fix it. (Trac #346, git 319debfb957641f311102739a15059f8453c54ce) -172. [func] jelte +172. [func] jelte Improved the bindctl cli in various ways, mainly concerning list and map item addressing, the correct display of actual values, and internal help. (Trac #384, git e5fb3bc1ed5f3c0aec6eb40a16c63f3d0fc6a7b2) -171. [func] feng, jerry, jinmei, vorner +171. [func] vorner b10-auth, src/lib/datasrc: in memory data source now works as a complete data source for authoritative DNS servers and b10-auth uses it. It still misses major features, however, including @@ -292,47 +292,47 @@ bind10-devel-20110224 released on February 24, 2011 correctly rejected. (Trac #117, git 9c690982f24fef19c747a72f43c4298333a58f48) -169. [func] zhang likun, jelte +169. [func] jelte Added a basic implementation for a resolver cache (though not used yet). (Trac #449, git 8aa3b2246ae095bbe7f855fd11656ae3bdb98986) -168. [bug] vorner +168. [bug] vorner Boss no longer has the -f argument, which was undocumented and stayed as a relict of previous versions, currently causing only strange behaviour. (Trac #572, git 17f237478961005707d649a661cc72a4a0d612d4) -167. [bug] naokikambe +167. [bug] naokikambe Fixed failure of termination of msgq_test.py with python3 coverage(3.3.1) (Trac #573, git 0e6a18e12f61cc482e07078776234f32605312e5) -166. [func] jelte +166. [func] jelte The resolver now sends back a SERVFAIL when there is a client timeout (timeout_client config setting), but it will not stop resolving (until there is a lookup timeout or a result). (Trac #497 and #489, git af0e5cd93bebb27cb5c4457f7759d12c8bf953a6) -165. [func] jelte +165. [func] jelte The resolver now handles CNAMEs, it will follow them, and include them in the answer. The maximum length of CNAME chains that is supported is 16. (Trac #497, git af0e5cd93bebb27cb5c4457f7759d12c8bf953a6) -164. [bug] y-aharen +164. [bug] y-aharen IntervalTimer: Modified the interface to accept interval in milliseconds. It shortens the time of the tests of IntervalTimer. (Trac #452, git c9f6acc81e24c4b8f0eb351123dc7b43f64e0914) -163. [func] vorner +163. [func] vorner The pimpl design pattern is used in UDPServer, with a shared pointer. This makes it smaller to copy (which is done a lot as a sideeffect of being coroutine) and speeds applications of this class (notably b10-auth) up by around 10%. (Trac #537, git 94cb95b1d508541201fc064302ba836164d3cbe6) -162. [func] stephen +162. [func] stephen Added C++ logging, allowing logging at different severities. Code specifies the message to be logged via a symbol, and the logging code picks up the message from an in-built dictionary. @@ -341,13 +341,13 @@ bind10-devel-20110224 released on February 24, 2011 to create message header files and supply the default messages. (Trac #438, git 7b1606cea7af15dc71f5ec1d70d958b00aa98af7) -161. [func] stephen +161. [func] stephen Added ResponseScrubber class to examine response from a server and to remove out-of-bailiwick RRsets. Also does cross-section checks to ensure consistency. (Trac #496, git b9296ca023cc9e76cda48a7eeebb0119166592c5) -160. [func] jelte +160. [func] jelte Updated the resolver to take 3 different timeout values; timeout_query for outstanding queries we sent while resolving timeout_client for sending an answer back to the client @@ -370,7 +370,7 @@ bind10-devel-20110224 released on February 24, 2011 of authoritative answers. (Trac #484, git 7b84de4c0e11f4a070e038ca4f093486e55622af) -157. [bug] vorner +157. [bug] vorner One frozen process no longer freezes the whole b10-msgq. It caused the whole system to stop working. (Trac #420, git 93697f58e4d912fa87bc7f9a591c1febc9e0d139) @@ -410,21 +410,21 @@ bind10-devel-20110120 released on January 20, 2011 sending statistics and stop responding to queries as a result. (Trac #513, git 285c5ee3d5582ed6df02d1aa00387f92a74e3695) -151. [bug] smann +151. [bug] smann lib/log/dummylog.h: lib/log/dummylog.cc: Modify dlog so that it takes an optional 2nd argument of type bool (true or false). This flag, if set, will cause the message to be printed whether or not -v is chosen. (trac #432, git 880220478c3e8702d56d761b1e0b21b77d08ee5a) -150. [bug] jelte +150. [bug] jelte b10-cfgmgr: No longer save the configuration on exit. Configuration is already saved if it is changed successfully, so writing it on exit (and hence, when nothing has changed too) is unnecessary and may even cause problems. (Trac #435, git fd7baa38c08d54d5b5f84930c1684c436d2776dc) -149. [bug] jelte +149. [bug] jelte bindctl: Check if the user session has disappeared (either by a timeout or by a server restart), and reauthenticate if so. This fixes the 'cmdctl not running' problem. @@ -485,7 +485,7 @@ bind10-devel-20110120 released on January 20, 2011 trailing garbage data in responses. This is a regression due to change #135. (Trac #462, svn r4081) -140. [func] y-aharen +140. [func] y-aharen src/bin/auth: Added a feature to count queries and send counter values to statistics periodically. To support it, added wrapping class of asio::deadline_timer to use as interval timer. @@ -496,7 +496,7 @@ bind10-devel-20110120 released on January 20, 2011 counters to b10-stats immediately. (Trac #347, svn r4026) -139. [build] jreed +139. [build] jreed Introduced configure option and make targets for generating Python code coverage report. This adds new make targets: report-python-coverage and clean-python-coverage. The C++ @@ -525,33 +525,33 @@ bind10-devel-20110120 released on January 20, 2011 so they use a msgq socket file in the build tree. (Trac #226, svn r3989) -136. [bug] jelte +136. [bug] jelte bindctl (and the configuration manager in general) now no longer accepts 'unknown' data; i.e. data for modules that it does not know about, or configuration items that are not specified in the .spec files. (Trac #202, svn r3967) -135. [func] each +135. [func] each Add b10-resolver. This is an example recursive server that currently does forwarding only and no caching. (Trac #327, svn r3903) -134. [func] vorner +134. [func] vorner b10-resolver supports timeouts and retries in forwarder mode. (Trac #401, svn r3660) -133. [func] vorner +133. [func] vorner New temporary logging function available in isc::log. It is used by b10-resolver. (Trac #393, r3602) -132. [func] vorner +132. [func] vorner The b10-resolver is configured through config manager. It has "listen_on" and "forward_addresses" options. (Trac #389, r3448) -131. [func] feng, jerry +131. [func] jerry src/lib/datasrc: Introduced two template classes RBTree and RBNode to provide the generic map with domain name as key and anything as the value. Because of some unresolved design issue, the new classes @@ -573,17 +573,17 @@ bind10-devel-20110120 released on January 20, 2011 any valid zone file into the acceptable form. (Trac #423, svn r3857) -128. [build] vorner +128. [build] vorner Test for query name = '.', type = DS to authoritative nameserver for root zone was added. (Trac #85, svn r3836) -127. [bug] stephen +127. [bug] stephen During normal operation process termination and resurrection messages are now output regardless of the state of the verbose flag. (Trac #229, svn r3828) -126. [func] stephen, vorner, ocean +126. [func] ocean The Nameserver Address Store (NSAS) component has been added. It takes care of choosing an IP address of a nameserver when a zone needs to be contacted. @@ -591,34 +591,34 @@ bind10-devel-20110120 released on January 20, 2011 bind10-devel-20101201 released on December 01, 2010 -125. [func] jelte +125. [func] jelte Added support for addressing individual list items in bindctl configuration commands; If you have an element that is a list, you - can use foo[X] to address a specific item, where X is an integer + can use foo[X] integer (starting at 0) (Trac #405, svn r3739) -124. [bug] jreed +124. [bug] jreed Fix some wrong version reporting. Now also show the version for the component and BIND 10 suite. (Trac #302, svn r3696) -123. [bug] jelte +123. [bug] jelte src/bin/bindctl printed values had the form of python literals (e.g. 'True'), while the input requires valid JSON (e.g. 'true'). Output changed to JSON format for consistency. (svn r3694) -122. [func] stephen +122. [func] stephen src/bin/bind10: Added configuration options to Boss to determine whether to start the authoritative server, recursive server (or both). A dummy program has been provided for test purposes. (Trac #412, svn r3676) -121. [func] jinmei +121. [func] jinmei src/lib/dns: Added support for TSIG RDATA. At this moment this is not much of real use, however, because no protocol support was added yet. It will soon be added. (Trac #372, svn r3649) -120. [func] jinmei +120. [func] jinmei src/lib/dns: introduced two new classes, TSIGKey and TSIGKeyRing, to manage TSIG keys. (Trac #381, svn r3622) @@ -639,7 +639,7 @@ bind10-devel-20101201 released on December 01, 2010 will be a more intuitive and less error prone behavior. This is a backward compatible change. (Trac #410, r3595) -117. [func] jinmei +117. [func] jinmei src/lib/datasrc: added new zone and zone table classes for the support of in memory data source. This is an intermediate step to the bigger feature, and is not yet actually usable in practice. @@ -675,20 +675,20 @@ bind10-devel-20101201 released on December 01, 2010 every poll_interval seconds, one socketpair is used to wake up the waiting server. (Trac #352, svn r3366) -111. [bug]* zhanglikun, Michal Vaner +111. [bug]* Vaner Make sure process xfrin/xfrout/zonemgr/cmdctl can be stopped properly when user enter "ctrl+c" or 'Boss shutdown' command through bindctl. The ZonemgrRefresh.run_timer and NotifyOut.dispatcher spawn a thread themselves. (Trac #335, svn r3273) -110. [func] Michal Vaner +110. [func] Vaner Added isc.net.check module to check ip addresses and ports for correctness and isc.net.addr to hold IP address. The bind10, xfrin and cmdctl programs are modified to use it. (Trac #353, svn r3240) -109. [func] naokikambe +109. [func] naokikambe Added the initial version of the stats module for the statistics feature of BIND 10, which supports the restricted features and items and reports via bindctl command. (Trac #191, r3218) @@ -700,17 +700,17 @@ bind10-devel-20101201 released on December 01, 2010 lowerbound_refresh, lowerbound_retry, max_transfer_timeout and jitter_scope. (Trac #340, r3205) -107. [func] zhang likun +107. [func] likun Remove the parameter 'db_file' for command 'retransfer' of xfrin module. xfrin.spec will not be generated by script. (Trac #329, r3171) -106. [bug] zhang likun +106. [bug] likun When xfrin can't connect with one zone's master, it should tell the bad news to zonemgr, so that zonemgr can reset the timer for that zone. (Trac #329, r3170) -105. [bug] Michal Vaner +105. [bug] Vaner Python processes: they no longer take 100% CPU while idle due to a busy loop in reading command session in a nonblocking way. (Trac #349, svn r3153), (Trac #382, svn r3294) @@ -732,7 +732,7 @@ bind10-devel-20101201 released on December 01, 2010 tests and documentation. API is mostly the same but the validation was a bit tightened. (Trac #351, svn r3056) -100. [func] Michal Vaner +100. [func] Vaner Python processes: support naming of python processes so they're not all called python3. (Trac #322, svn r3052) @@ -802,14 +802,14 @@ bind10-devel-20100917 released on September 17, 2010 Generate b10-config.db for tests at build time so that the source tree does not have to be writable. (Trac #315, r2776) -88. [func] jelte +88. [func] jelte Blocking reads on the msgq command channel now have a timeout (defaults to 4 seconds, modifiable as needed by modules). Because of this, modules will no longer block indefinitely if they are waiting for a message that is not sent for whatever reason. (Trac #296, r2761) -87. [func] zhanglikun +87. [func] zhanglikun lib/python/isc/notifyout: Add the feature of notify-out, when zone axfr/ixfr finishing, the server will notify its slaves. (Trac #289, svn r2737) @@ -912,11 +912,11 @@ bind10-devel-20100812 released on August 12, 2010 libpython whose path is unknown to run-time loader. NetBSD is a known such platform. (Trac #148, r2427) -71. [func] each +71. [func] each Add "-a" (address) option to bind10 to specify an address for the auth server to listen on. -70. [func] each +70. [func] each Added a hot-spot cache to libdatasrc to speed up access to repeatedly-queried data and reduce the number of queries to the underlying database; this should substantially improve @@ -926,14 +926,14 @@ bind10-devel-20100812 released on August 12, 2010 bind10-devel-20100701 released on July 1, 2010 -69. [func]* jelte +69. [func]* jelte Added python wrappers for libdns++ (isc::dns), and libxfr. This removes the dependency on Boost.Python. The wrappers don't completely implement all functionality, but the high-level API is wrapped, and current modules use it now. (Trac #181, svn r2361) -68. [func] zhanglikun +68. [func] zhanglikun Add options -c(--certificate-chain) to bindctl. Override class HTTPSConnection to support server certificate validation. Add support to cmdctl.spec file, now there are three configurable @@ -941,7 +941,7 @@ bind10-devel-20100701 released on July 1, 2010 all of them can be changed in runtime. (Trac #127, svn r2357) -67. [func] zhanglikun +67. [func] zhanglikun Make bindctl's command parser only do minimal check. Parameter value can be a sequence of non-space characters, or a string surrounded by quotation marks (these marks can @@ -952,13 +952,13 @@ bind10-devel-20100701 released on July 1, 2010 avoid using Exception to catch all exceptions. (Trac #220, svn r2356) -66. [bug] each +66. [bug] each Check for duplicate RRsets before inserting data into a message section; this, among other things, will prevent multiple copies of the same CNAME from showing up when there's a loop. (Trac #69, svn r2350) -65. [func] shentingting +65. [func] shentingting Various loadzone improvements: allow optional comment for $TTL, allow optional origin and comment for $INCLUDE, allow optional comment for $ORIGIN, support BIND9 extension of @@ -969,24 +969,24 @@ bind10-devel-20100701 released on July 1, 2010 formats to load. (Trac #197, #199, #244, #161, #198, #174, #175, svn r2340) -64. [func] jerry +64. [func] jerry Added python logging framework. It is for testing and experimenting with logging ideas. Currently, it supports three channels (file, syslog and stderr) and five levels (debug, info, warning, error and critical). (Trac #176, svn r2338) -63. [func] shane +63. [func] shane Added initial support for setuid(), using the "-u" flag. This will be replaced in the future, but for now provides a reasonable starting point. (Trac #180, svn r2330) -62. [func] jelte +62. [func] jelte bin/xfrin: Use the database_file as configured in Auth to transfers bin/xfrout: Use the database_file as configured in Auth to transfers -61. [bug] jelte +61. [bug] jelte bin/auth: Enable b10-auth to be launched in source tree (i.e. use a zone database file relative to that) @@ -1043,7 +1043,7 @@ bind10-devel-20100701 released on July 1, 2010 bind10-devel-20100602 released on June 2, 2010 -51. [build] jelte +51. [build] jelte lib/python: Add bind10_config.py module for paths and possibly other configure-time variables. Allow some components to find spec files in build tree when ran from source. @@ -1076,36 +1076,36 @@ bind10-devel-20100602 released on June 2, 2010 bin/bind10: Pass verbose option to more modules. (Trac #205, svn r1957) -44. [build] jreed +44. [build] jreed Install headers for libdns and libexception. (Trac #68, svn r1941) -43. [func] jelte +43. [func] jelte lib/cc: Message queuing on cc channel. (Trac #58, svn r1870) -42. [func] jelte +42. [func] jelte lib/python/isc/config: Make temporary file with python tempfile module instead of manual with fixed name. (Trac #184, svn r1859) -41. [func] jelte +41. [func] jelte Module descriptions in spec files. (Trac #90, svn r1856) -40. [build] jreed +40. [build] jreed Report detected features and configure settings at end of configure output. (svn r1836) -39. [func]* each +39. [func]* each Renamed libauth to libdatasrc. -38. [bug] zhanglikun +38. [bug] zhanglikun Send command 'shutdown' to Xfrin and Xfrout when boss receive SIGINT. Remove unused socket file when Xfrout process exits. Make sure Xfrout exit by itself when it receives SIGINT, instead of being killed by the signal SIGTERM or SIGKILL sent from boss. (Trac #135, #151, #134, svn r1797) -37. [build] jinmei +37. [build] jinmei Check for the availability of python-config. (Trac #159, svn r1794) @@ -1122,7 +1122,7 @@ bind10-devel-20100602 released on June 2, 2010 tests. Fixes include: IPv6 transport support, resource leak, and non IN class support. (Trac #185, svn r2000) -33. [bug] each +33. [bug] each bin/auth: output now prepended with "[b10-auth]" (Trac #109, svn r1985) From bcc0502a221ec06331c2825c5e27874626b32cf1 Mon Sep 17 00:00:00 2001 From: "Jeremy C. Reed" Date: Fri, 8 Apr 2011 10:52:48 -0500 Subject: [PATCH 56/72] [master] add a tab after entry description and before username Well this does make it not line up anymore for longer numbers/description types. But at least it is consistent for parsing. (Maybe should just use a single tab, but double is fine.) --- ChangeLog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a4bb8be97c..26421002ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -820,7 +820,7 @@ bind10-devel-20100917 released on September 17, 2010 timers and other information necessary for BIND10 to act as a slave. (Trac #215, svn r2737) -85. [build]* jinmei +85. [build]* jinmei Build programs using dynamic link by default. A new configure option --enable-static-link is provided to force static link for executable programs. Statically linked programs can be run on a @@ -834,7 +834,7 @@ bind10-devel-20100812 released on August 12, 2010 time because of connection problems. xfrout client will make a new connection every time. (Trac #299, svn r2697) -83. [build]* jreed +83. [build]* jreed The configure --with-boost-lib option is removed. It was not used since the build included ASIO. (svn r2684) From 71d23aa4207048dc78531ce48e35e6a83a6b62ab Mon Sep 17 00:00:00 2001 From: "Jeremy C. Reed" Date: Fri, 8 Apr 2011 11:07:32 -0500 Subject: [PATCH 57/72] [master] add some missing committer names for very old changelog entries In a few cases, the trac number or svn revision was missing, so I made a buest guess. --- ChangeLog | 58 +++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 26421002ad..4d11df2454 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1143,110 +1143,110 @@ bind10-devel-20100602 released on June 2, 2010 bind10-devel-20100421 released on April 21, 2010 -29. [build] +29. [build] jreed Enable Python unit tests for "make check". (svn r1762) -28. [bug] +28. [bug] jreed Fix msgq CC test so it can find its module. (svn r1751) -27. [build] +27. [build] jelte Add missing copyright license statements to various source files. (svn r1750) -26. [func] +26. [func] jelte Use PACKAGE_STRING (name + version) from config.h instead of hard-coded value in CH TXT version.bind replies (Trac #114, svn r1749) -25. [func]* +25. [func]* jreed Renamed msgq to b10-msgq. (Trac #25, svn r1747, r1748) -24. [func] +24. [func] jinmei Support case-sensitive name compression in MessageRenderer. (Trac #142, svn r1704) -23. [func] +23. [func] jinmei Support a simple name with possible compression. (svn r1701) -22. [func] +22. [func] zhanglikun b10-xfrout for AXFR-out support added. (svn r1629, r1630) -21. [bug] +21. [bug] zhanglikun Make log message more readable when xfrin failed. (svn r1697) -20. [bug] +20. [bug] jinmei Keep stderr for child processes if -v is specified. (svn r1690, r1698) -19. [bug] +19. [bug] jinmei Allow bind10 boss to pass environment variables from parent. (svn r1689) -18. [bug] +18. [bug] jinmei Xfrin warn if bind10_dns load failed. (svn r1688) -17. [bug] +17. [bug] jinmei Use sqlite3_ds.load() in xfrin module and catch Sqlite3DSError explicitly. (svn r1684) -16. [func]* +16. [func]* zhanglikun Removed print_message and print_settings configuration commands from Xfrin. (Trac #136, svn r1682) -15. [func]* +15. [func]* jinmei Changed zone loader/updater so trailing dot is not required. (svn r1681) -14. [bug] +14. [bug] shane Change shutdown to actually SIGKILL properly. (svn r1675) -13. [bug] +13. [bug] jinmei Don't ignore other RRs than SOA even if the second SOA is found. (svn r1674) -12. [build] +12. [build] jreed Fix tests and testdata so can be used from a read-only source directory. -11. [build] +11. [build] jreed Make sure python tests scripts are included in tarball. (svn r1648) -10. [build] +10. [build] jinmei Improve python detection for configure. (svn r1622) -9. [build] +9. [build] jinmei Automake the python binding of libdns. (svn r1617) -8. [bug] +8. [bug] zhanglikun Fix log errors which may cause xfrin module to crash. (svn r1613) -7. [func] +7. [func] zhanglikun New API for inserting zone data to sqlite3 database for AXFR-in. (svn r1612, r1613) -6. [bug] +6. [bug] jreed More code review, miscellaneous cleanups, style guidelines, and new and improved unit tests added. -5. [doc] +5. [doc] jreed Manual page cleanups and improvements. -4. [bug] +4. [bug] jinmei NSEC RDATA fixes for buffer overrun lookups, incorrect boundary checks, spec-non-conformant behaviors. (svn r1611) -3. [bug] +3. [bug] jelte Remove a re-raise of an exception that should only have been included in an error answer on the cc channel. (svn r1601) -2. [bug] +2. [bug] mgraff Removed unnecessary sleep() from ccsession.cc. (svn r1528) -1. [build]* +1. [build]* jreed The configure --with-boostlib option changed to --with-boost-lib. bind10-devel-20100319 released on March 19, 2010 From fcc5a1f450a3a0125e999a8bc9e1d26f207a8153 Mon Sep 17 00:00:00 2001 From: "Jeremy C. Reed" Date: Fri, 8 Apr 2011 11:19:04 -0500 Subject: [PATCH 58/72] [master] reformat some long lines in ChangeLog --- ChangeLog | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4d11df2454..1c8a2ec1e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,16 +5,16 @@ (Trac #363, git ce281e646be9f0f273229d94ccd75bf7e08d17cf) 216. [func] vorner - The BIND10_XFROUT_SOCKET_FILE environment variable can be used to specify - which socket should be used for communication between b10-auth and - b10-xfrout. Mostly for testing reasons. + The BIND10_XFROUT_SOCKET_FILE environment variable can be + used to specify which socket should be used for communication + between b10-auth and b10-xfrout. Mostly for testing reasons. (Trac #615, git 28b01ad5bf72472c824a7b8fc4a8dc394e22e462) 215. [func] vorner - A new process, b10-sockcreator, is added, which will create sockets for - the rest of the system. It is the only part which will need to keep the - root privileges. However, only the process exists, nothing can talk to it - yet. + A new process, b10-sockcreator, is added, which will create + sockets for the rest of the system. It is the only part + which will need to keep the root privileges. However, only + the process exists, nothing can talk to it yet. (Trac #366, git b509cbb77d31e388df68dfe52709d6edef93df3f) 214. [func]* vorner @@ -25,13 +25,14 @@ (Trac #670, git 7c1e4d5e1e28e556b1d10a8df8d9486971a3f052) 213. [bug] naokikambe - Solved incorrect datetime of "bind10.boot_time" and also added a new - command "sendstats" for Bob. This command is to send statistics data to - the stats daemon immediately. The solved problem is that statistics - data doesn't surely reach to the daemon because Bob sent statistics - data to the daemon while it is starting. So the daemon invokes the - command for Bob after it starts up. This command is also useful for - resending statistics data via bindctl manually. + Solved incorrect datetime of "bind10.boot_time" and also + added a new command "sendstats" for Bob. This command is + to send statistics data to the stats daemon immediately. + The solved problem is that statistics data doesn't surely + reach to the daemon because Bob sent statistics data to + the daemon while it is starting. So the daemon invokes the + command for Bob after it starts up. This command is also + useful for resending statistics data via bindctl manually. (Trac #521, git 1c269cbdc76f5dc2baeb43387c4d7ccc6dc863d2) 212. [bug] naokikambe @@ -412,9 +413,10 @@ bind10-devel-20110120 released on January 20, 2011 151. [bug] smann lib/log/dummylog.h: - lib/log/dummylog.cc: Modify dlog so that it takes an optional 2nd - argument of type bool (true or false). This flag, if set, will cause - the message to be printed whether or not -v is chosen. + lib/log/dummylog.cc: Modify dlog so that it takes an optional + 2nd argument of type bool (true or false). This flag, if + set, will cause the message to be printed whether or not + -v is chosen. (trac #432, git 880220478c3e8702d56d761b1e0b21b77d08ee5a) 150. [bug] jelte @@ -1265,10 +1267,10 @@ LEGEND unless it's deemed to be impossible or very hard to keep compatibility to fix the bug. [build] compilation and installation infrastructure change. -[doc] update to documentation. This shouldn't change run time behavior. +[doc] update to documentation. This shouldn't change run time behavior. [func] new feature. In some cases this may be a backward incompatible change, which would require a bump of major version. -[security] security hole fix. This is no different than a general bug fix - except that it will be handled as confidential and will cause +[security] security hole fix. This is no different than a general bug + fix except that it will be handled as confidential and will cause security patch releases. *: Backward incompatible or operational change. From 25fe349f4fb12f444c06fdc2117a4f62f1dda2f7 Mon Sep 17 00:00:00 2001 From: "Jeremy C. Reed" Date: Fri, 8 Apr 2011 11:20:55 -0500 Subject: [PATCH 59/72] [master] miscellaneous punctuation and case improvements --- ChangeLog | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c8a2ec1e4..a7d1e1c774 100644 --- a/ChangeLog +++ b/ChangeLog @@ -283,7 +283,7 @@ bind10-devel-20110224 released on February 24, 2011 complete data source for authoritative DNS servers and b10-auth uses it. It still misses major features, however, including DNSSEC support and zone transfer. - (Last trac #553, but many more, + (Last Trac #553, but many more, git 6f031a09a248e7684723c000f3e8cc981dcdb349) 170. [bug] jinmei @@ -306,7 +306,7 @@ bind10-devel-20110224 released on February 24, 2011 167. [bug] naokikambe Fixed failure of termination of msgq_test.py with python3 - coverage(3.3.1) + coverage (3.3.1). (Trac #573, git 0e6a18e12f61cc482e07078776234f32605312e5) 166. [func] jelte @@ -417,7 +417,7 @@ bind10-devel-20110120 released on January 20, 2011 2nd argument of type bool (true or false). This flag, if set, will cause the message to be printed whether or not -v is chosen. - (trac #432, git 880220478c3e8702d56d761b1e0b21b77d08ee5a) + (Trac #432, git 880220478c3e8702d56d761b1e0b21b77d08ee5a) 150. [bug] jelte b10-cfgmgr: No longer save the configuration on exit. Configuration @@ -430,7 +430,7 @@ bind10-devel-20110120 released on January 20, 2011 bindctl: Check if the user session has disappeared (either by a timeout or by a server restart), and reauthenticate if so. This fixes the 'cmdctl not running' problem. - (trac #431, git b929be82fec5f92e115d8985552f84b4fdd385b9) + (Trac #431, git b929be82fec5f92e115d8985552f84b4fdd385b9) 148. [func] jelte bindctl: Command results are now pretty-printed (i.e. printed in @@ -564,8 +564,8 @@ bind10-devel-20110120 released on January 20, 2011 src/lib/datasrc: Introduced a new class MemoryDataSrc to provide the general interface for memory data source. For the initial implementation, we don't make it a derived class of AbstractDataSrc - because the interface is so different(we'll eventually consider this - as part of the generalization work). + because the interface is so different (we'll eventually + consider this as part of the generalization work). (Trac #422, svn r3866) 129. [func] jinmei @@ -883,7 +883,7 @@ bind10-devel-20100812 released on August 12, 2010 77. [func] zhanglikun Make error message be more friendly when running cmdctl and it's - already running(listening on same port)(Trac #277, r2540) + already running (listening on same port)(Trac #277, r2540) 76. [bug] jelte Fixed a bug in the handling of 'remote' config modules (i.e. @@ -936,7 +936,7 @@ bind10-devel-20100701 released on July 1, 2010 (Trac #181, svn r2361) 68. [func] zhanglikun - Add options -c(--certificate-chain) to bindctl. Override class + Add options -c (--certificate-chain) to bindctl. Override class HTTPSConnection to support server certificate validation. Add support to cmdctl.spec file, now there are three configurable items for cmdctl: 'key_file', 'cert_file' and 'accounts_file', From 429ade576746b5c5e1d9113ae57ee863276809b1 Mon Sep 17 00:00:00 2001 From: "Jeremy C. Reed" Date: Fri, 8 Apr 2011 11:24:53 -0500 Subject: [PATCH 60/72] [master] mention last release date. --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index a7d1e1c774..8e5d60e968 100644 --- a/ChangeLog +++ b/ChangeLog @@ -50,6 +50,8 @@ additional glue records for ANSWER section. (Trac #699, git 510924ebc57def8085cc0e5413deda990b2abeee) +bind10-devel-20110322 released on March 22, 2011 + 209. [func] jelte Resolver now uses the NSAS when looking for a nameserver to query for any specific zone. This also includes keeping track of From 1e3b465d617d7e7dc9c9ac2427e37a1b837369d9 Mon Sep 17 00:00:00 2001 From: Stephen Morris Date: Fri, 8 Apr 2011 17:36:30 +0100 Subject: [PATCH 61/72] [trac708_test] Added tests for the RTT problem Added a test to check that the RTT is being calculated correctly. --- src/lib/resolve/recursive_query.cc | 31 ++++++++---- src/lib/resolve/recursive_query.h | 48 +++++++++++++++++-- .../tests/recursive_query_unittest_2.cc | 17 ++++++- 3 files changed, 83 insertions(+), 13 deletions(-) diff --git a/src/lib/resolve/recursive_query.cc b/src/lib/resolve/recursive_query.cc index 0ee5813318..30ce6bd875 100644 --- a/src/lib/resolve/recursive_query.cc +++ b/src/lib/resolve/recursive_query.cc @@ -57,19 +57,19 @@ RecursiveQuery::RecursiveQuery(DNSService& dns_service, const std::vector >& upstream, const std::vector >& upstream_root, int query_timeout, int client_timeout, int lookup_timeout, - unsigned retries) : + unsigned retries) + : dns_service_(dns_service), nsas_(nsas), cache_(cache), upstream_(new AddressVector(upstream)), upstream_root_(new AddressVector(upstream_root)), test_server_("", 0), query_timeout_(query_timeout), client_timeout_(client_timeout), - lookup_timeout_(lookup_timeout), retries_(retries) + lookup_timeout_(lookup_timeout), retries_(retries), rtt_recorder_() { } // Set the test server - only used for unit testing. - void RecursiveQuery::setTestServer(const std::string& address, uint16_t port) { dlog("Setting test server to " + address + "(" + @@ -78,6 +78,11 @@ RecursiveQuery::setTestServer(const std::string& address, uint16_t port) { test_server_.second = port; } +// Set the RTT recorder - only used for testing +void +RecursiveQuery::setRttRecorder(boost::shared_ptr& recorder) { + rtt_recorder_ = recorder; +} namespace { @@ -223,6 +228,10 @@ private: // event; we can cancel the NSAS callback safely. size_t outstanding_events_; + // RTT Recorder. Used for testing, the RTTs of queries are + // sent to this object as well as being used to update the NSAS. + boost::shared_ptr rtt_recorder_; + // perform a single lookup; first we check the cache to see // if we have a response for our query stored already. if // so, call handlerecursiveresponse(), if not, we call send() @@ -481,7 +490,9 @@ public: int query_timeout, int client_timeout, int lookup_timeout, unsigned retries, isc::nsas::NameserverAddressStore& nsas, - isc::cache::ResolverCache& cache) : + isc::cache::ResolverCache& cache, + boost::shared_ptr& recorder) + : io_(io), question_(question), answer_message_(answer_message), @@ -502,7 +513,8 @@ public: cur_zone_("."), nsas_callback_(new ResolverNSASCallback(this)), nsas_callback_out_(false), - outstanding_events_(0) + outstanding_events_(0), + rtt_recorder_(recorder) { // Setup the timer to stop trying (lookup_timeout) if (lookup_timeout >= 0) { @@ -619,9 +631,11 @@ public: rtt = 1000 * (cur_time.tv_sec - current_ns_qsent_time.tv_sec); rtt += (cur_time.tv_usec - current_ns_qsent_time.tv_usec) / 1000; } - dlog("RTT: " + boost::lexical_cast(rtt)); current_ns_address.updateRTT(rtt); + if (rtt_recorder_) { + rtt_recorder_->addRtt(rtt); + } try { Message incoming(Message::PARSE); @@ -739,7 +753,8 @@ RecursiveQuery::resolve(const QuestionPtr& question, new RunningQuery(io, *question, answer_message, upstream_, test_server_, buffer, callback, query_timeout_, client_timeout_, - lookup_timeout_, retries_, nsas_, cache_); + lookup_timeout_, retries_, nsas_, + cache_, rtt_recorder_); } } } @@ -792,7 +807,7 @@ RecursiveQuery::resolve(const Question& question, new RunningQuery(io, question, answer_message, upstream_, test_server_, buffer, crs, query_timeout_, client_timeout_, lookup_timeout_, retries_, - nsas_, cache_); + nsas_, cache_, rtt_recorder_); } } } diff --git a/src/lib/resolve/recursive_query.h b/src/lib/resolve/recursive_query.h index 1180d5599f..720375c375 100644 --- a/src/lib/resolve/recursive_query.h +++ b/src/lib/resolve/recursive_query.h @@ -22,11 +22,42 @@ #include namespace asiolink { -/// \brief The \c RecursiveQuery class provides a layer of abstraction around -/// the ASIO code that carries out an upstream query. + + +/// \brief RTT Recorder /// -/// This design is very preliminary; currently it is only capable of -/// handling simple forward requests to a single resolver. +/// Used for testing, this class will hold the set of round-trip times to +/// nameservers for the current recursive query. +/// +/// A pointer to an object of this class is passed to RecursiveQuery which in +/// turn passes it to the created RunningQuery class. When a running query +/// completes, its RTT is passed to the RTT Recorder object. +class RttRecorder { +public: + /// \brief Record Time + /// + /// Adds a round-trip time to the internal vector of times. + /// + /// \param RTT to record. + void addRtt(uint32_t rtt) { + rtt_.push_back(rtt); + } + + /// \brief Return RTT Vector + std::vector getRtt() const { + return rtt_; + } + +private: + std::vector rtt_; ///< Stored round-trip times +}; + + +/// \brief Recursive Query +/// +/// The \c RecursiveQuery class provides a layer of abstraction around +/// the ASIO code that carries out an upstream query. + class RecursiveQuery { /// /// \name Constructors @@ -65,6 +96,14 @@ public: unsigned retries = 3); //@} + /// \brief Set Round-Trip Time Recorder + /// + /// Sets the RTT recorder object. This is not accessed directly, instead + /// it is passed to created RunningQuery objects. + /// + /// \param recorder Pointer to the RTT recorder object used to hold RTTs. + void setRttRecorder(boost::shared_ptr& recorder); + /// \brief Initiate resolving /// /// When sendQuery() is called, a (set of) message(s) is sent @@ -127,6 +166,7 @@ private: int client_timeout_; int lookup_timeout_; unsigned retries_; + boost::shared_ptr rtt_recorder_; ///< Round-trip time recorder }; } // namespace asiolink diff --git a/src/lib/resolve/tests/recursive_query_unittest_2.cc b/src/lib/resolve/tests/recursive_query_unittest_2.cc index 643c5a3aa2..95af7b5fb3 100644 --- a/src/lib/resolve/tests/recursive_query_unittest_2.cc +++ b/src/lib/resolve/tests/recursive_query_unittest_2.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -649,13 +650,17 @@ TEST_F(RecursiveQueryTest2, Resolve) { boost::bind(&RecursiveQueryTest2::tcpAcceptHandler, this, _1, 0)); - // Set up the RecursiveQuery object. + // Set up the RecursiveQuery object. We will also test that it correctly records + // RTT times by setting up a RTT recorder object as well. std::vector > upstream; // Empty std::vector > upstream_root; // Empty RecursiveQuery query(dns_service_, *nsas_, cache_, upstream, upstream_root); query.setTestServer(TEST_ADDRESS, TEST_PORT); + boost::shared_ptr recorder(new RttRecorder()); + query.setRttRecorder(recorder); + // Set up callback to receive notification that the query has completed. isc::resolve::ResolverInterface::CallbackPtr resolver_callback(new ResolverCallback(service_)); @@ -672,6 +677,16 @@ TEST_F(RecursiveQueryTest2, Resolve) { ResolverCallback* rc = static_cast(resolver_callback.get()); EXPECT_TRUE(rc->getRun()); EXPECT_TRUE(rc->getStatus()); + + // Finally, check that all the RTTs were "reasonable" (defined here as + // being below 2 seconds). This is an explicit check to test that the + // variables in the RTT calculation are at least being initialized; if they + // weren't, we would expect some absurdly high answers. + vector rtt = recorder->getRtt(); + EXPECT_GT(rtt.size(), 0); + for (int i = 0; i < rtt.size(); ++i) { + EXPECT_LT(rtt[i], 2000); + } } } // namespace asiolink From 0e519f4da5ef99475c3bf5941ed1ea553a7c9a6e Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Fri, 8 Apr 2011 18:05:56 -0700 Subject: [PATCH 62/72] [trac806] initial implementation of the RP RDATA support with tests --- src/lib/dns/rdata/generic/rp_17.cc | 116 +++++++++++++ src/lib/dns/rdata/generic/rp_17.h | 88 ++++++++++ src/lib/dns/tests/Makefile.am | 1 + src/lib/dns/tests/rdata_rp_unittest.cc | 159 ++++++++++++++++++ src/lib/dns/tests/testdata/Makefile.am | 8 + .../tests/testdata/rdata_rp_fromWire1.spec | 6 + .../tests/testdata/rdata_rp_fromWire2.spec | 12 ++ .../tests/testdata/rdata_rp_fromWire3.spec | 7 + .../tests/testdata/rdata_rp_fromWire4.spec | 7 + .../tests/testdata/rdata_rp_fromWire5.spec | 7 + .../tests/testdata/rdata_rp_fromWire6.spec | 7 + .../dns/tests/testdata/rdata_rp_toWire1.spec | 8 + .../dns/tests/testdata/rdata_rp_toWire2.spec | 14 ++ 13 files changed, 440 insertions(+) create mode 100644 src/lib/dns/rdata/generic/rp_17.cc create mode 100644 src/lib/dns/rdata/generic/rp_17.h create mode 100644 src/lib/dns/tests/rdata_rp_unittest.cc create mode 100644 src/lib/dns/tests/testdata/rdata_rp_fromWire1.spec create mode 100644 src/lib/dns/tests/testdata/rdata_rp_fromWire2.spec create mode 100644 src/lib/dns/tests/testdata/rdata_rp_fromWire3.spec create mode 100644 src/lib/dns/tests/testdata/rdata_rp_fromWire4.spec create mode 100644 src/lib/dns/tests/testdata/rdata_rp_fromWire5.spec create mode 100644 src/lib/dns/tests/testdata/rdata_rp_fromWire6.spec create mode 100644 src/lib/dns/tests/testdata/rdata_rp_toWire1.spec create mode 100644 src/lib/dns/tests/testdata/rdata_rp_toWire2.spec diff --git a/src/lib/dns/rdata/generic/rp_17.cc b/src/lib/dns/rdata/generic/rp_17.cc new file mode 100644 index 0000000000..fdd0ff8066 --- /dev/null +++ b/src/lib/dns/rdata/generic/rp_17.cc @@ -0,0 +1,116 @@ +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; +using namespace isc::dns; + +// BEGIN_ISC_NAMESPACE +// BEGIN_RDATA_NAMESPACE + +/// \brief Constructor from string. +/// +/// \c rp_str must be formatted as follows: +/// \code +/// \endcode +/// where both fields must represent a valid domain name. +/// +/// \exception InvalidRdataText The number of RDATA fields (must be 2) is +/// incorrect. +/// \exception Other The constructor of the \c Name class will throw if the +/// given name is invalid. +/// \exception std::bad_alloc Memory allocation for names fails. +RP::RP(const std::string& rp_str) : + // We cannot construct both names in the initialization list due to the + // necessary text processing, so we have to initialize them with a dummy + // name and replace them later. + mailbox_(Name::ROOT_NAME()), text_(Name::ROOT_NAME()) +{ + istringstream iss(rp_str); + string mailbox_str, text_str; + iss >> mailbox_str >> text_str; + + // Validation: A valid RP RR must have exactly two fields. + if (iss.bad() || iss.fail()) { + isc_throw(InvalidRdataText, "Invalid RP text: " << rp_str); + } + if (!iss.eof()) { + isc_throw(InvalidRdataText, "Invalid RP text (redundant field): " + << rp_str); + } + + mailbox_ = Name(mailbox_str); + text_ = Name(text_str); +} + +/// \brief Constructor from wire-format data. +/// +/// This constructor doesn't check the validity of the second parameter (rdata +/// length) for parsing. +/// If necessary, the caller will check consistency. +/// +/// \exception std::bad_alloc Memory allocation for names fails. +/// \exception Other The constructor of the \c Name class will throw if the +/// names in the wire is invalid. +RP::RP(InputBuffer& buffer, size_t) : mailbox_(buffer), text_(buffer) { +} + +/// \brief Convert the \c RP to a string. +/// +/// The output of this method is formatted as described in the "from string" +/// constructor (\c RP(const std::string&))). +/// +/// \exception std::bad_alloc Internal resource allocation fails. +/// +/// \return A \c string object that represents the \c RP object. +std::string +RP::toText() const { + return (mailbox_.toText() + " " + text_.toText()); +} + +void +RP::toWire(OutputBuffer& buffer) const { + mailbox_.toWire(buffer); + text_.toWire(buffer); +} + +void +RP::toWire(MessageRenderer& renderer) const { + // Type RP is not "well-known", and name compression must be disabled + // per RFC3597. + renderer.writeName(mailbox_, false); + renderer.writeName(text_, false); +} + +int +RP::compare(const Rdata& other) const { + const RP& other_rp = dynamic_cast(other); + + const int cmp = compareNames(mailbox_, other_rp.mailbox_); + if (cmp != 0) { + return (cmp); + } + return (compareNames(text_, other_rp.text_)); +} + +// END_RDATA_NAMESPACE +// END_ISC_NAMESPACE diff --git a/src/lib/dns/rdata/generic/rp_17.h b/src/lib/dns/rdata/generic/rp_17.h new file mode 100644 index 0000000000..a90a530673 --- /dev/null +++ b/src/lib/dns/rdata/generic/rp_17.h @@ -0,0 +1,88 @@ +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +// BEGIN_HEADER_GUARD + +#include + +#include +#include + +// BEGIN_ISC_NAMESPACE + +// BEGIN_COMMON_DECLARATIONS +// END_COMMON_DECLARATIONS + +// BEGIN_RDATA_NAMESPACE + +/// \brief \c rdata::generic::RP class represents the RP RDATA as defined in +/// RFC1183. +/// +/// This class implements the basic interfaces inherited from the abstract +/// \c rdata::Rdata class, and provides trivial accessors specific to the +/// RP RDATA. +class RP : public Rdata { +public: + // BEGIN_COMMON_MEMBERS + // END_COMMON_MEMBERS + + /// We use the default copy constructor and assignment operator. + + /// \brief Constructor from RDATA field parameters. + /// + /// The parameters are a straightforward mapping of %RP RDATA + /// fields as defined in RFC1183. + RP(const Name& mailbox, const Name& text) : + mailbox_(mailbox), text_(text) + {} + + /// \brief Return the value of the mailbox field. + /// + /// This method normally does not throw an exception, but if resource + /// allocation for the returned \c Name object fails, a corresponding + /// standard exception will be thrown. + /// + /// \note + /// Unlike the case of some other RDATA classes (such as + /// \c NS::getNSName()), this method constructs a new \c Name object + /// and returns it, instead of returning a reference to a \c Name object + /// internally maintained in the class (which is a private member). + /// This is based on the observation that this method will be rarely used + /// and even when it's used it will not be in a performance context + /// (for example, a recursive resolver won't need this field in its + /// resolution process). By returning a new object we have flexibility of + /// changing the internal representation without the risk of changing + /// the interface or method property. + /// The same note applies to the \c getText() method. + Name getMailbox() const { return (mailbox_); } + + /// \brief Return the value of the text field. + /// + /// This method normally does not throw an exception, but if resource + /// allocation for the returned \c Name object fails, a corresponding + /// standard exception will be thrown. + Name getText() const { return (text_); } + +private: + Name mailbox_; + Name text_; +}; + +// END_RDATA_NAMESPACE +// END_ISC_NAMESPACE +// END_HEADER_GUARD + +// Local Variables: +// mode: c++ +// End: diff --git a/src/lib/dns/tests/Makefile.am b/src/lib/dns/tests/Makefile.am index 246adb7a3a..2bd7c87422 100644 --- a/src/lib/dns/tests/Makefile.am +++ b/src/lib/dns/tests/Makefile.am @@ -39,6 +39,7 @@ run_unittests_SOURCES += rdata_nsec3_unittest.cc run_unittests_SOURCES += rdata_nsecbitmap_unittest.cc run_unittests_SOURCES += rdata_nsec3param_unittest.cc run_unittests_SOURCES += rdata_rrsig_unittest.cc +run_unittests_SOURCES += rdata_rp_unittest.cc run_unittests_SOURCES += rdata_tsig_unittest.cc run_unittests_SOURCES += rrset_unittest.cc rrsetlist_unittest.cc run_unittests_SOURCES += question_unittest.cc diff --git a/src/lib/dns/tests/rdata_rp_unittest.cc b/src/lib/dns/tests/rdata_rp_unittest.cc new file mode 100644 index 0000000000..d32030a93f --- /dev/null +++ b/src/lib/dns/tests/rdata_rp_unittest.cc @@ -0,0 +1,159 @@ +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include + +#include +#include +#include + +#include + +#include +#include + +using isc::UnitTestUtil; +using namespace std; +using namespace isc::dns; +using namespace isc::dns::rdata; + +namespace { +class Rdata_RP_Test : public RdataTest { +protected: + Rdata_RP_Test() : + mailbox_name("root.example.com."), + text_name("rp-text.example.com."), + // this also serves as a test for "from text" constructor in a normal + // case. + rdata_rp("root.example.com. rp-text.example.com."), + obuffer(0), renderer(obuffer) + {} + + const Name mailbox_name, text_name; + const generic::RP rdata_rp; // commonly used test RDATA + OutputBuffer obuffer; + MessageRenderer renderer; + vector expected_wire; +}; + +TEST_F(Rdata_RP_Test, createFromText) { + EXPECT_EQ(mailbox_name, rdata_rp.getMailbox()); + EXPECT_EQ(text_name, rdata_rp.getText()); + + // Invalid textual input cases follow: + // names are invalid + EXPECT_THROW(generic::RP("bad..name. rp-text.example.com"), EmptyLabel); + EXPECT_THROW(generic::RP("mailbox.example.com. bad..name"), EmptyLabel); + + // missing field + EXPECT_THROW(generic::RP("mailbox.example.com."), InvalidRdataText); + + // redundant field + EXPECT_THROW(generic::RP("mailbox.example.com. rp-text.example.com. " + "redundant.example."), InvalidRdataText); +} + +TEST_F(Rdata_RP_Test, createFromWire) { + RdataPtr rdata(rdataFactoryFromFile(RRType::RP(), RRClass::IN(), + "rdata_rp_fromWire1.wire")); + EXPECT_EQ(mailbox_name, dynamic_cast(*rdata).getMailbox()); + EXPECT_EQ(text_name, dynamic_cast(*rdata).getText()); + + // a similar test with names being compressed + rdata = rdataFactoryFromFile(RRType::RP(), RRClass::IN(), + "rdata_rp_fromWire2.wire", 30); + EXPECT_EQ(mailbox_name, dynamic_cast(*rdata).getMailbox()); + EXPECT_EQ(Name("rp-text.example.net"), + dynamic_cast(*rdata).getText()); +} + +TEST_F(Rdata_RP_Test, badFromWire) { + // RDLEN is too short + EXPECT_THROW(rdataFactoryFromFile(RRType::RP(), RRClass::IN(), + "rdata_rp_fromWire3.wire"), + InvalidRdataLength); + + // RDLEN is too long + EXPECT_THROW(rdataFactoryFromFile(RRType::RP(), RRClass::IN(), + "rdata_rp_fromWire4.wire"), + InvalidRdataLength); + + // bogus mailbox name + EXPECT_THROW(rdataFactoryFromFile(RRType::RP(), RRClass::IN(), + "rdata_rp_fromWire5.wire"), + DNSMessageFORMERR); + + // bogus text name + EXPECT_THROW(rdataFactoryFromFile(RRType::RP(), RRClass::IN(), + "rdata_rp_fromWire6.wire"), + DNSMessageFORMERR); +} + +TEST_F(Rdata_RP_Test, createFromParams) { + EXPECT_EQ(mailbox_name, generic::RP(mailbox_name, text_name).getMailbox()); + EXPECT_EQ(text_name, generic::RP(mailbox_name, text_name).getText()); +} + +TEST_F(Rdata_RP_Test, toWireBuffer) { + // construct expected data + UnitTestUtil::readWireData("rdata_rp_toWire1.wire", expected_wire); + + // construct actual data + rdata_rp.toWire(obuffer); + + // then compare them + EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, + obuffer.getData(), obuffer.getLength(), + &expected_wire[0], expected_wire.size()); +} + +TEST_F(Rdata_RP_Test, toWireRenderer) { + // similar to toWireBuffer, but names in RDATA should be compressed. + UnitTestUtil::readWireData("rdata_rp_toWire2.wire", expected_wire); + + renderer.writeName(Name("a.example.com")); + renderer.writeName(Name("b.example.net")); + generic::RP(mailbox_name, Name("rp-text.example.net")).toWire(renderer); + EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData, + renderer.getData(), renderer.getLength(), + &expected_wire[0], expected_wire.size()); +} + +TEST_F(Rdata_RP_Test, toText) { + // there's not much to test for this method. Only checking a simple case. + EXPECT_EQ("root.example.com. rp-text.example.com.", rdata_rp.toText()); +} + +TEST_F(Rdata_RP_Test, compare) { + // check reflexivity + EXPECT_EQ(0, rdata_rp.compare(rdata_rp)); + + // names must be compared in case-insensitive manner + EXPECT_EQ(0, rdata_rp.compare(generic::RP("ROOT.example.com. " + "rp-text.EXAMPLE.com."))); + + // another RP whose mailbox name is larger than that of rdata_rp. + const generic::RP large1_rp("zzzz.example.com. rp-text.example.com."); + EXPECT_GT(0, rdata_rp.compare(large1_rp)); + EXPECT_LT(0, large1_rp.compare(rdata_rp)); + + // yet another RP whose text name is larger than that of rdata_rp. + const generic::RP large2_rp("root.example.com. zzzzzzz.example.com."); + EXPECT_GT(0, rdata_rp.compare(large2_rp)); + EXPECT_LT(0, large2_rp.compare(rdata_rp)); + + // comparison attempt between incompatible RR types should be rejected + EXPECT_THROW(rdata_rp.compare(*RdataTest::rdata_nomatch), bad_cast); +} +} diff --git a/src/lib/dns/tests/testdata/Makefile.am b/src/lib/dns/tests/testdata/Makefile.am index 1aaddb68b0..1dc1c003cc 100644 --- a/src/lib/dns/tests/testdata/Makefile.am +++ b/src/lib/dns/tests/testdata/Makefile.am @@ -16,6 +16,10 @@ BUILT_SOURCES += rdata_nsec3_fromWire10.wire rdata_nsec3_fromWire11.wire BUILT_SOURCES += rdata_nsec3_fromWire12.wire rdata_nsec3_fromWire13.wire BUILT_SOURCES += rdata_nsec3_fromWire14.wire rdata_nsec3_fromWire15.wire BUILT_SOURCES += rdata_rrsig_fromWire2.wire +BUILT_SOURCES += rdata_rp_fromWire1.wire rdata_rp_fromWire2.wire +BUILT_SOURCES += rdata_rp_fromWire3.wire rdata_rp_fromWire4.wire +BUILT_SOURCES += rdata_rp_fromWire5.wire rdata_rp_fromWire6.wire +BUILT_SOURCES += rdata_rp_toWire1.wire rdata_rp_toWire2.wire BUILT_SOURCES += rdata_soa_toWireUncompressed.wire BUILT_SOURCES += rdata_txt_fromWire2.wire rdata_txt_fromWire3.wire BUILT_SOURCES += rdata_txt_fromWire4.wire rdata_txt_fromWire5.wire @@ -67,6 +71,10 @@ EXTRA_DIST += rdata_nsec3_fromWire12.spec rdata_nsec3_fromWire13.spec EXTRA_DIST += rdata_nsec3_fromWire14.spec rdata_nsec3_fromWire15.spec EXTRA_DIST += rdata_opt_fromWire rdata_rrsig_fromWire1 EXTRA_DIST += rdata_rrsig_fromWire2.spec +EXTRA_DIST += rdata_rp_fromWire1.spec rdata_rp_fromWire2.spec +EXTRA_DIST += rdata_rp_fromWire3.spec rdata_rp_fromWire4.spec +EXTRA_DIST += rdata_rp_fromWire5.spec rdata_rp_fromWire6.spec +EXTRA_DIST += rdata_rp_toWire1.spec rdata_rp_toWire2.spec EXTRA_DIST += rdata_soa_fromWire rdata_soa_toWireUncompressed.spec EXTRA_DIST += rdata_txt_fromWire1 rdata_txt_fromWire2.spec EXTRA_DIST += rdata_txt_fromWire3.spec rdata_txt_fromWire4.spec diff --git a/src/lib/dns/tests/testdata/rdata_rp_fromWire1.spec b/src/lib/dns/tests/testdata/rdata_rp_fromWire1.spec new file mode 100644 index 0000000000..edb9f345be --- /dev/null +++ b/src/lib/dns/tests/testdata/rdata_rp_fromWire1.spec @@ -0,0 +1,6 @@ +# +# A simplest form of RP: all default parameters +# +[custom] +sections: rp +[rp] diff --git a/src/lib/dns/tests/testdata/rdata_rp_fromWire2.spec b/src/lib/dns/tests/testdata/rdata_rp_fromWire2.spec new file mode 100644 index 0000000000..57adb5a0a0 --- /dev/null +++ b/src/lib/dns/tests/testdata/rdata_rp_fromWire2.spec @@ -0,0 +1,12 @@ +# +# A simplest form of RP: names are compressed. +# +[custom] +sections: name/1:name/2:rp +[name/1] +name: a.example.com +[name/2] +name: b.example.net +[rp] +mailbox: root.ptr=2 +text: rp-text.ptr=17 diff --git a/src/lib/dns/tests/testdata/rdata_rp_fromWire3.spec b/src/lib/dns/tests/testdata/rdata_rp_fromWire3.spec new file mode 100644 index 0000000000..a238b7e2c5 --- /dev/null +++ b/src/lib/dns/tests/testdata/rdata_rp_fromWire3.spec @@ -0,0 +1,7 @@ +# +# RP-like RDATA but RDLEN is too short. +# +[custom] +sections: rp +[rp] +rdlen: 38 diff --git a/src/lib/dns/tests/testdata/rdata_rp_fromWire4.spec b/src/lib/dns/tests/testdata/rdata_rp_fromWire4.spec new file mode 100644 index 0000000000..6f3abd1a3a --- /dev/null +++ b/src/lib/dns/tests/testdata/rdata_rp_fromWire4.spec @@ -0,0 +1,7 @@ +# +# RP-like RDATA but RDLEN is too long. +# +[custom] +sections: rp +[rp] +rdlen: 40 diff --git a/src/lib/dns/tests/testdata/rdata_rp_fromWire5.spec b/src/lib/dns/tests/testdata/rdata_rp_fromWire5.spec new file mode 100644 index 0000000000..b8d5e29cc0 --- /dev/null +++ b/src/lib/dns/tests/testdata/rdata_rp_fromWire5.spec @@ -0,0 +1,7 @@ +# +# RP-like RDATA but mailbox name is broken. +# +[custom] +sections: rp +[rp] +mailbox: "01234567890123456789012345678901234567890123456789012345678901234" diff --git a/src/lib/dns/tests/testdata/rdata_rp_fromWire6.spec b/src/lib/dns/tests/testdata/rdata_rp_fromWire6.spec new file mode 100644 index 0000000000..e9e79f30f7 --- /dev/null +++ b/src/lib/dns/tests/testdata/rdata_rp_fromWire6.spec @@ -0,0 +1,7 @@ +# +# RP-like RDATA but text name is broken. +# +[custom] +sections: rp +[rp] +text: "01234567890123456789012345678901234567890123456789012345678901234" diff --git a/src/lib/dns/tests/testdata/rdata_rp_toWire1.spec b/src/lib/dns/tests/testdata/rdata_rp_toWire1.spec new file mode 100644 index 0000000000..948bd1ad5c --- /dev/null +++ b/src/lib/dns/tests/testdata/rdata_rp_toWire1.spec @@ -0,0 +1,8 @@ +# +# A simplest form of RP for toWire test: all default parameters except rdlen, +# which is to be omitted. +# +[custom] +sections: rp +[rp] +rdlen: -1 diff --git a/src/lib/dns/tests/testdata/rdata_rp_toWire2.spec b/src/lib/dns/tests/testdata/rdata_rp_toWire2.spec new file mode 100644 index 0000000000..09a7ddc255 --- /dev/null +++ b/src/lib/dns/tests/testdata/rdata_rp_toWire2.spec @@ -0,0 +1,14 @@ +# +# A simple form of RP: names could be compressed (but MUST NOT). +# rdlen is omitted for the "to wire" test. +# +[custom] +sections: name/1:name/2:rp +[name/1] +name: a.example.com +[name/2] +name: b.example.net +[rp] +rdlen: -1 +mailbox: root.example.com +text: rp-text.example.net From 0a2a239a12af8c0ee54d62cb34d170c6cfdd33f9 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Fri, 8 Apr 2011 18:11:39 -0700 Subject: [PATCH 63/72] [trac806] added support for RP RDATA to gen-wiredata tool. Also changed the output format for compressed name (remove the space betwen the non pointer and pointer parts) in order to simplify the length calculation. --- src/lib/dns/tests/testdata/gen-wiredata.py.in | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/lib/dns/tests/testdata/gen-wiredata.py.in b/src/lib/dns/tests/testdata/gen-wiredata.py.in index 645430c63f..72cbdaaedd 100755 --- a/src/lib/dns/tests/testdata/gen-wiredata.py.in +++ b/src/lib/dns/tests/testdata/gen-wiredata.py.in @@ -90,7 +90,7 @@ def encode_name(name, absolute=True): for l in labels: if len(l) > 4 and l[0:4] == 'ptr=': # special meta-syntax for compression pointer - wire += ' %04x' % (0xc000 | int(l[4:])) + wire += '%04x' % (0xc000 | int(l[4:])) break if absolute or len(l) > 0: wire += '%02x' % len(l) @@ -277,6 +277,34 @@ class TXT: ' ' if len(wirestring_list[i]) > 0 else '', wirestring_list[i])) +class RP: + '''Implements rendering RP RDATA in the wire format. + Configurable parameters are as follows: + - rdlen: 16-bit RDATA length. If omitted, the accurate value is auto + calculated and used; if negative, the RDLEN field will be omitted from + the output data. + - mailbox: The mailbox field. + - text: The text field. + All of these parameters have the default values and can be omitted. + ''' + rdlen = None # auto-calculate + mailbox = 'root.example.com' + text = 'rp-text.example.com' + def dump(self, f): + mailbox_wire = encode_name(self.mailbox) + text_wire = encode_name(self.text) + if self.rdlen is None: + self.rdlen = (len(mailbox_wire) + len(text_wire)) / 2 + else: + self.rdlen = int(self.rdlen) + if self.rdlen >= 0: + f.write('\n# RP RDATA (RDLEN=%d)\n' % self.rdlen) + f.write('%04x\n' % self.rdlen) + else: + f.write('\n# RP RDATA (RDLEN omitted)\n') + f.write('# MAILBOX=%s TEXT=%s\n' % (self.mailbox, self.text)) + f.write('%s %s\n' % (mailbox_wire, text_wire)) + class NSECBASE: '''Implements rendering NSEC/NSEC3 type bitmaps commonly used for these RRs. The NSEC and NSEC3 classes will be inherited from this @@ -461,8 +489,9 @@ def get_config_param(section): 'header' : (DNSHeader, header_xtables), 'question' : (DNSQuestion, question_xtables), 'edns' : (EDNS, {}), 'soa' : (SOA, {}), 'txt' : (TXT, {}), - 'rrsig' : (RRSIG, {}), 'nsec' : (NSEC, {}), - 'nsec3' : (NSEC3, {}), 'tsig' : (TSIG, {}) } + 'rp' : (RP, {}), 'rrsig' : (RRSIG, {}), + 'nsec' : (NSEC, {}), 'nsec3' : (NSEC3, {}), + 'tsig' : (TSIG, {}) } s = section m = re.match('^([^:]+)/\d+$', section) if m: From 31b96198427b2c140556afcd61ff3809c43266f6 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 9 Apr 2011 10:48:23 -0700 Subject: [PATCH 64/72] [trac806] added blank lines for better readability --- src/lib/dns/rdata.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/dns/rdata.h b/src/lib/dns/rdata.h index 8eaedd39a5..0908c75fb1 100644 --- a/src/lib/dns/rdata.h +++ b/src/lib/dns/rdata.h @@ -161,6 +161,7 @@ public: /// /// \return A string representation of \c Rdata. virtual std::string toText() const = 0; + /// \brief Render the \c Rdata in the wire format into a buffer. /// /// This is a pure virtual method without the definition; the actual @@ -169,6 +170,7 @@ public: /// /// \param buffer An output buffer to store the wire data. virtual void toWire(OutputBuffer& buffer) const = 0; + /// \brief Render the \c Rdata in the wire format into a /// \c MessageRenderer object. /// @@ -251,6 +253,7 @@ public: /// \param rdata_string A string of textual representation of generic /// RDATA. explicit Generic(const std::string& rdata_string); + /// /// \brief Constructor from wire-format data. /// @@ -273,6 +276,7 @@ public: /// \c Rdata to parse. /// \param rdata_len The length in buffer of the \c Rdata. In bytes. Generic(InputBuffer& buffer, size_t rdata_len); + /// /// \brief The destructor. virtual ~Generic(); @@ -284,6 +288,7 @@ public: /// /// \param source A reference to a \c generic::Generic object to copy from. Generic(const Generic& source); + /// /// \brief The assignment operator. /// @@ -293,6 +298,7 @@ public: /// \param source A reference to a \c generic::Generic object to copy from. Generic& operator=(const Generic& source); //@} + /// /// \name Converter methods /// @@ -307,6 +313,7 @@ public: /// /// \return A string representation of \c generic::Generic. virtual std::string toText() const; + /// /// \brief Render the \c generic::Generic in the wire format into a buffer. /// @@ -317,6 +324,7 @@ public: /// /// \param buffer An output buffer to store the wire data. virtual void toWire(OutputBuffer& buffer) const; + /// \brief Render the \c generic::Generic in the wire format into a /// \c MessageRenderer object. /// @@ -329,6 +337,7 @@ public: /// output buffer in which the \c Generic object is to be stored. virtual void toWire(MessageRenderer& renderer) const; //@} + /// /// \name Comparison method /// @@ -421,6 +430,7 @@ std::ostream& operator<<(std::ostream& os, const Generic& rdata); /// object. RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass, const std::string& rdata_string); + /// \brief Create RDATA of a given pair of RR type and class from /// wire-format data. /// @@ -444,6 +454,7 @@ RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass, /// object. RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass, InputBuffer& buffer, size_t len); + /// \brief Create RDATA of a given pair of RR type and class, copying /// of another RDATA of same kind. /// From fb99e325e667a39ef88b6c8fab128a8df862a786 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Sat, 9 Apr 2011 10:52:25 -0700 Subject: [PATCH 65/72] [trac806] corrected comments in Rdata_RP_Test.toWireRenderer about compression. the previous one was wrong due to naive copy-paste. --- src/lib/dns/tests/rdata_rp_unittest.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/dns/tests/rdata_rp_unittest.cc b/src/lib/dns/tests/rdata_rp_unittest.cc index d32030a93f..52285f17c4 100644 --- a/src/lib/dns/tests/rdata_rp_unittest.cc +++ b/src/lib/dns/tests/rdata_rp_unittest.cc @@ -119,7 +119,10 @@ TEST_F(Rdata_RP_Test, toWireBuffer) { } TEST_F(Rdata_RP_Test, toWireRenderer) { - // similar to toWireBuffer, but names in RDATA should be compressed. + // similar to toWireBuffer, but names in RDATA could be compressed due to + // preceding names. Actually they must not be compressed according to + // RFC3597, and this test checks that. + UnitTestUtil::readWireData("rdata_rp_toWire2.wire", expected_wire); renderer.writeName(Name("a.example.com")); From ad04d070072126a8f221f67244e9a54e68b53955 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Mon, 11 Apr 2011 01:30:52 -0700 Subject: [PATCH 66/72] [trac806] explicitly defined the copy constructor. --- src/lib/dns/rdata/generic/rp_17.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/dns/rdata/generic/rp_17.cc b/src/lib/dns/rdata/generic/rp_17.cc index fdd0ff8066..5b39dc3218 100644 --- a/src/lib/dns/rdata/generic/rp_17.cc +++ b/src/lib/dns/rdata/generic/rp_17.cc @@ -74,6 +74,14 @@ RP::RP(const std::string& rp_str) : RP::RP(InputBuffer& buffer, size_t) : mailbox_(buffer), text_(buffer) { } +/// \brief Copy constructor. +/// +/// \exception std::bad_alloc Memory allocation fails in copying internal +/// member variables (this should be very rare). +RP::RP(const RP& other) : + Rdata(), mailbox_(other.mailbox_), text_(other.text_) +{} + /// \brief Convert the \c RP to a string. /// /// The output of this method is formatted as described in the "from string" From bf0a9b3576da038ee53bd49360fe3bd8b01189fd Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Mon, 11 Apr 2011 11:18:37 -0700 Subject: [PATCH 67/72] [master] added changelog entry for #806 --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8e5d60e968..749b5c3fa1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +218. [func] jinmei + src/lib/dns: added support for RP RDATA. + (Trac #806, git 4e47d5f6b692c63c907af6681a75024450884a88) + 217. [bug] jerry src/lib/dns/python: Use a signed version of larger size of integer and perform more strict range checks with PyArg_ParseTuple() in case of From a83e29a881af14dc61b366024e25f5ca68244220 Mon Sep 17 00:00:00 2001 From: "Jeremy C. Reed" Date: Mon, 11 Apr 2011 19:12:32 -0500 Subject: [PATCH 68/72] [master] add -I for builddir to find generated spec_config.h. Add -I flag for builddir to find generated spec_config.h. Also remove the ../spec_config.h target. It didn't work as-is since it referenced file in the wrong directory. Instead of fixing this I decided to remove. In normal build, the previous directory does build it first. In the case of attempting to build specific directories first, doesn't work yet due to other problems already (like missing dns components). This was noticed in a failed distcheck. --- src/bin/auth/tests/Makefile.am | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/bin/auth/tests/Makefile.am b/src/bin/auth/tests/Makefile.am index 22c9c02915..882f7fdf3b 100644 --- a/src/bin/auth/tests/Makefile.am +++ b/src/bin/auth/tests/Makefile.am @@ -1,4 +1,5 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +AM_CPPFLAGS += -I$(top_builddir)/src/bin # for generated spec_config.h header AM_CPPFLAGS += -I$(top_builddir)/src/lib/dns -I$(top_srcdir)/src/bin AM_CPPFLAGS += -I$(top_builddir)/src/lib/cc AM_CPPFLAGS += $(BOOST_INCLUDES) @@ -16,10 +17,6 @@ CLEANFILES = *.gcno *.gcda TESTS = if HAVE_GTEST -../spec_config.h: ../spec_config.h.pre - $(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" spec_config.h.pre >$@ - -CLEANFILES += ../spec_config.h BUILT_SOURCES = ../spec_config.h TESTS += run_unittests From e23c4b1e90ba1127a5b7eaef4add6f3b68fbc6fa Mon Sep 17 00:00:00 2001 From: "Jeremy C. Reed" Date: Mon, 11 Apr 2011 19:17:07 -0500 Subject: [PATCH 69/72] [master] This uses generated test script, so run from the builddir. This uses generated test script, so run from the builddir. But now this is slightly different from other test makefiles. --- src/bin/bind10/tests/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bin/bind10/tests/Makefile.am b/src/bin/bind10/tests/Makefile.am index d05d977595..34d809ab24 100644 --- a/src/bin/bind10/tests/Makefile.am +++ b/src/bin/bind10/tests/Makefile.am @@ -1,5 +1,6 @@ PYCOVERAGE_RUN = @PYCOVERAGE_RUN@ #PYTESTS = args_test.py bind10_test.py +# NOTE: this has a generated test found in the builddir PYTESTS = bind10_test.py EXTRA_DIST = $(PYTESTS) @@ -14,5 +15,5 @@ endif echo Running test: $$pytest ; \ env PYTHONPATH=$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python:$(abs_top_builddir)/src/bin/bind10 \ BIND10_MSGQ_SOCKET_FILE=$(abs_top_builddir)/msgq_socket \ - $(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ; \ + $(PYCOVERAGE_RUN) $(abs_builddir)/$$pytest || exit ; \ done From c20ca2440575e5cfc9d4a3dd582c9f56776452d6 Mon Sep 17 00:00:00 2001 From: qiaojing Date: Tue, 12 Apr 2011 14:42:29 +0800 Subject: [PATCH 70/72] [trac609] --- tools/query_cmp/README | 27 + tools/query_cmp/queries/dquery01 | 394 + tools/query_cmp/queries/dquery01_no-type | 316 + tools/query_cmp/queries/dquery01_non-terminal | 317 + tools/query_cmp/queries/dquery01_nxdomain | 316 + tools/query_cmp/src/lib/compare_rrset.py | 285 + tools/query_cmp/src/lib/handledns.py | 284 + tools/query_cmp/src/lib/read_query.py | 93 + tools/query_cmp/src/query_two_server.py | 102 + tools/query_cmp/zonefile/example.com.txt | 1298 ++++ .../query_cmp/zonefile/example.com.txt.signed | 6858 +++++++++++++++++ 11 files changed, 10290 insertions(+) create mode 100644 tools/query_cmp/README create mode 100644 tools/query_cmp/queries/dquery01 create mode 100644 tools/query_cmp/queries/dquery01_no-type create mode 100644 tools/query_cmp/queries/dquery01_non-terminal create mode 100644 tools/query_cmp/queries/dquery01_nxdomain create mode 100755 tools/query_cmp/src/lib/compare_rrset.py create mode 100755 tools/query_cmp/src/lib/handledns.py create mode 100755 tools/query_cmp/src/lib/read_query.py create mode 100755 tools/query_cmp/src/query_two_server.py create mode 100644 tools/query_cmp/zonefile/example.com.txt create mode 100644 tools/query_cmp/zonefile/example.com.txt.signed diff --git a/tools/query_cmp/README b/tools/query_cmp/README new file mode 100644 index 0000000000..bd3efccc2a --- /dev/null +++ b/tools/query_cmp/README @@ -0,0 +1,27 @@ +This is a tool to compare two DNS server's response to query. + +DIRECTORY STRUCTURE + +zonefile + The file under this directory is for the testee servers + to load before running the test, containing various types + of RRs in the test cases. It is in bind9's format. One + file is signed while the other is not, which you can choose. + +queries + The files under this directory are the input of the test, + involving various types of query cases. + +src + The scripts of this test. + It uses the dns python binding interface of bind10 from the + source tree, so src/lib/dns/python/.libs must be added to + PYTHONPATH environment variable ahead of running the tests. + +RUNNING + +e.g. +cd src +./query_two_server.py -u -f ../queries/dquery01 -s 10.10.1.1 -p 30000 -t 10.10.10.2 -q 30002 > bind10test_normal + +./query_two_server.py --help' for more details diff --git a/tools/query_cmp/queries/dquery01 b/tools/query_cmp/queries/dquery01 new file mode 100644 index 0000000000..923ba7dff2 --- /dev/null +++ b/tools/query_cmp/queries/dquery01 @@ -0,0 +1,394 @@ +# Fields Description +# +#query:ID QR OPCODE AA TC RD RA Z AD CD RCODE QDCOUNT ANCOUNT NSCOUNT ARCOUNT QNAME QTYPE QCLASS +#response:ID QR OPCODE AA TC RD RA Z AD CD RCODE QDCOUNT ANCOUNT NSCOUNT ARCOUNT QNAME QTYPE QCLASS +# := .. +# := NAME TYPE CLASS TTL RDLENGTH +# := ADDRESS | +# NSDNAME | +# MNAME RNAME SERIAL REFRESH RETRY EXPIRE MINIMUM | +# ... +# := .. +# := .. +# +# +# +# Description in BNF (http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form) +# ::=
+#
::= +# +# ::= +# +# ::=
+# ::= +# ::= +# ::= +# ::= { } +# ::= +# ::= | "" +# ::=