diff --git a/ChangeLog b/ChangeLog index 5ddfe3dd30..749b5c3fa1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,97 +1,123 @@ - 214. [func]* vorner +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 + overflows. + (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. + (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. + (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 - 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. +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. (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. + 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 +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 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 @@ -99,42 +125,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 @@ -144,51 +170,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 @@ -198,46 +224,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] 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"). @@ -246,74 +272,74 @@ 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] 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 DNSSEC support and zone transfer. - (Last trac #553, but many more, + (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] 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) + 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. @@ -322,13 +348,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 @@ -336,14 +362,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 @@ -351,24 +377,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 @@ -377,12 +403,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 @@ -391,46 +417,47 @@ 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) + 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) + (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 @@ -439,7 +466,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 @@ -450,23 +477,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. @@ -477,14 +504,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" @@ -501,70 +528,70 @@ 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] 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 - 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 +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] 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. @@ -572,38 +599,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 + 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) - 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 @@ -613,158 +640,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]* 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) 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] 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) - 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] 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 @@ -772,36 +799,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 @@ -810,34 +837,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 @@ -849,7 +876,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 @@ -860,44 +887,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) + 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 @@ -907,22 +934,22 @@ 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 - Add options -c(--certificate-chain) to bindctl. Override class +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 items for cmdctl: 'key_file', 'cert_file' and 'accounts_file', 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 @@ -933,13 +960,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 @@ -950,71 +977,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 @@ -1024,210 +1051,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] 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 @@ -1246,10 +1273,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. diff --git a/configure.ac b/configure.ac index 64db689e01..8e30987c78 100644 --- a/configure.ac +++ b/configure.ac @@ -624,6 +624,8 @@ AC_CONFIG_FILES([Makefile src/bin/auth/benchmarks/Makefile src/bin/resolver/Makefile src/bin/resolver/tests/Makefile + src/bin/sockcreator/Makefile + src/bin/sockcreator/tests/Makefile src/bin/xfrin/Makefile src/bin/xfrin/tests/Makefile src/bin/xfrout/Makefile @@ -694,6 +696,10 @@ AC_CONFIG_FILES([Makefile src/lib/server_common/tests/Makefile tests/Makefile tests/system/Makefile + src/lib/util/Makefile + src/lib/util/io/Makefile + src/lib/util/io/tests/Makefile + src/lib/util/unittests/Makefile ]) AC_OUTPUT([doc/version.ent src/bin/cfgmgr/b10-cfgmgr.py @@ -708,6 +714,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/doc/Doxyfile b/doc/Doxyfile index 46aa1780a8..83e85b823e 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -568,7 +568,11 @@ 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/bin/resolver ../src/lib/bench ../src/lib/log ../src/lib/asiolink/ ../src/lib/nsas ../src/lib/testutils ../src/lib/cache ../src/lib/server_common/ +INPUT = ../src/lib/cc ../src/lib/config ../src/lib/dns \ + ../src/lib/exceptions ../src/lib/datasrc ../src/bin/auth \ + ../src/bin/resolver ../src/lib/bench ../src/lib/log ../src/lib/asiolink/ \ + ../src/lib/nsas ../src/lib/testutils ../src/lib/cache \ + ../src/lib/server_common/ ../src/bin/sockcreator/ ../src/lib/util/ # 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 1768ce708b..23d660cd0d 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 stats tests resolver + usermgr zonemgr stats tests resolver sockcreator check-recursive: all-recursive diff --git a/src/bin/auth/Makefile.am b/src/bin/auth/Makefile.am index 92758297a3..56dc348f21 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 += auth_config.cc auth_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..35381a1d49 --- /dev/null +++ b/src/bin/auth/common.cc @@ -0,0 +1,36 @@ +// 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(getenv("B10_FROM_SOURCE_LOCALSTATEDIR")) + + "/auth_xfrout_conn"); + } else { + return (string(getenv("B10_FROM_BUILD")) + "/auth_xfrout_conn"); + } + } else { + if (getenv("BIND10_XFROUT_SOCKET_FILE")) { + return (getenv("BIND10_XFROUT_SOCKET_FILE")); + } 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 b8edac85da..9bb0b456cf 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 @@ -124,19 +124,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 3a5511b330..026dde3c5c 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,6 +17,8 @@ CLEANFILES = *.gcno *.gcda TESTS = if HAVE_GTEST + +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 @@ -24,10 +27,13 @@ run_unittests_SOURCES += ../query.h ../query.cc 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 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"); +} + +} diff --git a/src/bin/bind10/bind10.8 b/src/bin/bind10/bind10.8 index b275f2dced..d5ab9053b3 100644 --- a/src/bin/bind10/bind10.8 +++ b/src/bin/bind10/bind10.8 @@ -2,12 +2,12 @@ .\" Title: bind10 .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.75.2 -.\" Date: February 22, 2011 +.\" Date: March 31, 2011 .\" Manual: BIND10 .\" Source: BIND10 .\" Language: English .\" -.TH "BIND10" "8" "February 22, 2011" "BIND10" "BIND10" +.TH "BIND10" "8" "March 31, 2011" "BIND10" "BIND10" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- @@ -22,7 +22,7 @@ bind10 \- BIND 10 boss process .SH "SYNOPSIS" .HP \w'\fBbind10\fR\ 'u -\fBbind10\fR [\fB\-m\ \fR\fB\fIfile\fR\fR] [\fB\-n\fR] [\fB\-u\ \fR\fB\fIuser\fR\fR] [\fB\-v\fR] [\fB\-\-msgq\-socket\-file\ \fR\fB\fIfile\fR\fR] [\fB\-\-no\-cache\fR] [\fB\-\-user\ \fR\fB\fIuser\fR\fR] [\fB\-\-pretty\-name\ \fR\fB\fIname\fR\fR] [\fB\-\-brittle\fR] [\fB\-\-verbose\fR] +\fBbind10\fR [\fB\-c\ \fR\fB\fIconfig\-filename\fR\fR] [\fB\-m\ \fR\fB\fIfile\fR\fR] [\fB\-n\fR] [\fB\-p\ \fR\fB\fIdata_path\fR\fR] [\fB\-u\ \fR\fB\fIuser\fR\fR] [\fB\-v\fR] [\fB\-\-brittle\fR] [\fB\-\-cmdctl\-port\fR\ \fIport\fR] [\fB\-\-config\-file\fR\ \fIconfig\-filename\fR] [\fB\-\-data\-path\fR\ \fIdirectory\fR] [\fB\-\-msgq\-socket\-file\ \fR\fB\fIfile\fR\fR] [\fB\-\-no\-cache\fR] [\fB\-\-pid\-file\fR\ \fIfilename\fR] [\fB\-\-pretty\-name\ \fR\fB\fIname\fR\fR] [\fB\-\-user\ \fR\fB\fIuser\fR\fR] [\fB\-\-verbose\fR] .SH "DESCRIPTION" .PP The @@ -32,6 +32,34 @@ daemon starts up other BIND 10 required daemons\&. It handles restarting of exit .PP The arguments are as follows: .PP +\fB\-\-brittle\fR +.RS 4 +Shutdown if any of the child processes of +\fBbind10\fR +exit\&. This is intended to help developers debug the server, and should not be used in production\&. +.RE +.PP +\fB\-c\fR \fIconfig\-filename\fR, \fB\-\-config\-file\fR \fIconfig\-filename\fR +.RS 4 +The configuration filename to use\&. Can be either absolute or relative to data path\&. In case it is absolute, value of data path is not considered\&. +.sp +Defaults to b10\-config\&.db\&. +.RE +.PP +\fB\-\-cmdctl\-port\fR \fIport\fR +.RS 4 +The +\fBb10\-cmdctl\fR +daemon will listen on this port\&. (See +b10\-cmdctl(8) +for the default\&.) +.RE +.PP +\fB\-p\fR \fIdirectory\fR, \fB\-\-data\-path\fR \fIdirectory\fR +.RS 4 +The path where BIND 10 programs look for various data files\&. Currently only b10\-cfgmgr uses it to locate the configuration file, but the usage might be extended for other programs and other types of files\&. +.RE +.PP \fB\-m\fR \fIfile\fR, \fB\-\-msgq\-socket\-file\fR \fIfile\fR .RS 4 The UNIX domain socket file for the @@ -57,6 +85,13 @@ to run as\&. must be initially ran as the root user to use this option\&. The default is to run as the current user\&. .RE .PP +\fB\-\-pid\-file\fR \fIfilename\fR +.RS 4 +If defined, the PID of the +\fBbind10\fR +is stored in this file\&. This is used for testing purposes\&. +.RE +.PP \fB\-\-pretty\-name \fR\fB\fIname\fR\fR .RS 4 The name this process should have in tools like @@ -66,14 +101,6 @@ or \fBbind10\fR\&. .RE .PP -\fB\-\-brittle\fR -.RS 4 -Shutdown if any of the child processes of -\fBbind10\fR -exit\&. This is intended to help developers debug the server, and should -not be used in production. -.RE -.PP \fB\-v\fR, \fB\-\-verbose\fR .RS 4 Display more about what is going on for diff --git a/src/bin/bind10/bind10.xml b/src/bin/bind10/bind10.xml index 6331503a7a..1128264ece 100644 --- a/src/bin/bind10/bind10.xml +++ b/src/bin/bind10/bind10.xml @@ -20,7 +20,7 @@ - February 22, 2011 + March 31, 2011 @@ -44,16 +44,21 @@ bind10 + + - - + + port + config-filename + directory - + filename + @@ -82,9 +87,24 @@ The arguments are as follows: + - config-filename, + + + + + Shutdown if any of the child processes of + bind10 exit. This is intended to + help developers debug the server, and should not be + used in production. + + + + + + + config-filename, config-filename @@ -97,8 +117,22 @@ - data-path, - data-path + port + + + The b10-cmdctl daemon will listen + on this port. + (See + b10-cmdctl8 + for the default.) + + + + + + + directory, + directory The path where BIND 10 programs look for various data files. @@ -134,7 +168,6 @@ user, name - The username for bind10 to run as. @@ -144,6 +177,16 @@ + + filename + + If defined, the PID of the bind10 is stored + in this file. + This is used for testing purposes. + + + + 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 diff --git a/src/bin/sockcreator/Makefile.am b/src/bin/sockcreator/Makefile.am new file mode 100644 index 0000000000..1ac46401f2 --- /dev/null +++ b/src/bin/sockcreator/Makefile.am @@ -0,0 +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/README b/src/bin/sockcreator/README new file mode 100644 index 0000000000..4dbbee726e --- /dev/null +++ b/src/bin/sockcreator/README @@ -0,0 +1,49 @@ +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. + +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 + 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' 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): + +* '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). diff --git a/src/lib/xfr/python_xfr.cc b/src/bin/sockcreator/main.cc similarity index 56% rename from src/lib/xfr/python_xfr.cc rename to src/bin/sockcreator/main.cc index 52848ad852..37da30394d 100644 --- a/src/lib/xfr/python_xfr.cc +++ b/src/bin/sockcreator/main.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 @@ -12,21 +12,15 @@ // 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 -#include +#include "sockcreator.h" -#include +using namespace isc::socket_creator; -using namespace isc::xfr; -using namespace boost::python; - -BOOST_PYTHON_MODULE(bind10_xfr) { - def("recv_fd", &recv_fd); - def("send_fd", &send_fd); +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..6b50813f4f --- /dev/null +++ b/src/bin/sockcreator/sockcreator.cc @@ -0,0 +1,151 @@ +// 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 "sockcreator.h" + +#include + +#include +#include +#include +#include +#include +#include + +using namespace isc::util::io; + +namespace isc { +namespace socket_creator { + +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) { + return -1; + } + if (bind(sock, bind_addr, addr_len) == -1) { + return -2; + } + return sock; +} + +// 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 { \ + 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; + 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); + // FIXME: Check the output and write a test for it + 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 + } + } +} + +} // End of the namespaces +} diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h new file mode 100644 index 0000000000..ddf9a090d7 --- /dev/null +++ b/src/bin/sockcreator/sockcreator.h @@ -0,0 +1,100 @@ +// 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. + +/** + * \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 +#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 addr_len The actual length of bind_addr. + */ +int +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); + +/** + * 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. + * + * Current errors are: + * - 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. + * + * \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 = isc::util::io::send_fd); + +} // End of the namespaces +} + +#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..2e1307ad20 --- /dev/null +++ b/src/bin/sockcreator/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 = ../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) +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/run_unittests.cc b/src/bin/sockcreator/tests/run_unittests.cc new file mode 100644 index 0000000000..e787ab1cb1 --- /dev/null +++ b/src/bin/sockcreator/tests/run_unittests.cc @@ -0,0 +1,22 @@ +// 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 + +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..73cbf48df6 --- /dev/null +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -0,0 +1,273 @@ +// 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 "../sockcreator.h" + +#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 { + +/* + * 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, FAMILY_FIELD, \ + 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); \ + addr.FAMILY_FIELD = ADDR_FAMILY; \ + struct sockaddr *addr_ptr = static_cast( \ + static_cast(&addr)); \ + \ + 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 error " << strerror(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_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)); \ + } 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)) << \ + "Send failed with error " << strerror(errno) << " on socket " << \ + SOCKET; \ + char buffer[5]; \ + ASSERT_EQ(5, recv(SOCKET, buffer, 5, 0)) << \ + "Recv failed with error " << strerror(errno) << " on socket " << \ + SOCKET; \ + 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, sin_family, INADDR_SET, + UDP_CHECK); +} + +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. + */ +TEST(get_sock, fail_with_nonsense) { + struct sockaddr addr; + memset(&addr, 0, sizeof addr); + ASSERT_LT(get_sock(0, &addr, sizeof addr), 0); +} + +/* + * Helper functions to pass to run during testing. + */ +int +get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t) +{ + int result(0); + int port(0); + /* + * 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; + } else { + return 0; + } +} + +/* + * 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(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"; + 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 { + 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[4 + sizeof(int) * 2]; + // 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); +} + +} diff --git a/src/bin/xfrout/tests/Makefile.am b/src/bin/xfrout/tests/Makefile.am index 01f2e400c9..76c59778d7 100644 --- a/src/bin/xfrout/tests/Makefile.am +++ b/src/bin/xfrout/tests/Makefile.am @@ -6,7 +6,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 # test using command-line arguments, so use check-local target instead of TESTS @@ -18,7 +18,7 @@ if ENABLE_PYTHON_COVERAGE endif 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_RUN) $(abs_srcdir)/$$pytest || exit ; \ done 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..17ca3ebff9 100755 --- a/src/bin/xfrout/xfrout.py.in +++ b/src/bin/xfrout/xfrout.py.in @@ -37,29 +37,38 @@ from optparse import OptionParser, OptionValueError from isc.util import socketserver_mixin 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.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" @@ -376,7 +385,7 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn, ThreadingUnixStreamServer): # This may happen when one xfrout process try to connect to # xfrout unix socket server, to check whether there is another # xfrout running. - if sock_fd == XFR_FD_RECEIVE_FAIL: + if sock_fd == FD_COMM_ERROR: self._log.log_message("error", "Failed to receive the file descriptor for XFR connection") return diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 8ef2fd0e94..c8a38ec7c2 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = exceptions dns cc config python xfr bench log asiolink \ +SUBDIRS = exceptions dns cc config util python xfr bench log asiolink \ asiodns nsas cache resolve testutils datasrc server_common diff --git a/src/lib/datasrc/tests/rbtree_unittest.cc b/src/lib/datasrc/tests/rbtree_unittest.cc index dd1b7fe04e..b26a22bc5f 100644 --- a/src/lib/datasrc/tests/rbtree_unittest.cc +++ b/src/lib/datasrc/tests/rbtree_unittest.cc @@ -398,7 +398,7 @@ TEST_F(RBTreeTest, getLastComparedNode) { EXPECT_EQ(static_cast(NULL), chain.getLastComparedNode()); chain.clear(); - const RBNode* expected_node; + const RBNode* expected_node = NULL; // Exact match case. The returned node should be last compared. EXPECT_EQ(RBTree::EXACTMATCH, diff --git a/src/lib/dns/buffer.h b/src/lib/dns/buffer.h index c8241545f8..46a9bf4e13 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,15 +288,58 @@ 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 && len != 0) { + 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 && allocated_ != 0) { + throw std::bad_alloc(); + } + memcpy(buffer_, other.buffer_, size_); + } + + /// \brief Destructor + ~ OutputBuffer() { + free(buffer_); + } //@} + /// \brief Assignment operator + OutputBuffer& operator =(const OutputBuffer& other) { + uint8_t* newbuff(static_cast(malloc(other.allocated_))); + if (newbuff == NULL && other.allocated_ != 0) { + throw std::bad_alloc(); + } + free(buffer_); + buffer_ = newbuff; + size_ = other.size_; + allocated_ = other.allocated_; + memcpy(buffer_, other.buffer_, size_); + return (*this); + } + /// /// \name Getter Methods /// //@{ /// \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 @@ -302,21 +347,21 @@ 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 /// 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 >= data_.size()) { + if (pos >= size_) { isc_throw(InvalidBufferPosition, "read at invalid position"); } - return (data_[pos]); + return (buffer_[pos]); } //@} @@ -330,7 +375,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. /// @@ -341,20 +389,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 8-bit integer into the buffer. /// @@ -365,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 @@ -377,8 +428,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. @@ -393,12 +445,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. @@ -406,10 +458,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. /// @@ -419,13 +472,38 @@ 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; } //@} - + private: - std::vector data_; + // 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 + 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 diff --git a/src/lib/dns/python/edns_python.cc b/src/lib/dns/python/edns_python.cc index e54dba0d23..82db8d80bb 100644 --- a/src/lib/dns/python/edns_python.cc +++ b/src/lib/dns/python/edns_python.cc @@ -297,12 +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) { - PyErr_SetString(PyExc_OverflowError, + if (size < 0 || size > 0xffff) { + 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 e19547e17b..97bc28dac0 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; - - if (PyArg_ParseTuple(args, "I", &i)) { + int i; + + if (PyArg_ParseTuple(args, "i", &i)) { PyErr_Clear(); if (i == Message::PARSE) { self->message = new Message(Message::PARSE); @@ -274,17 +274,17 @@ 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_SetString(PyExc_ValueError, "Message header flag out of range"); return (NULL); } @@ -310,10 +310,19 @@ Message_getQid(s_Message* self) { static PyObject* Message_setQid(s_Message* self, PyObject* args) { - uint16_t id; - if (!PyArg_ParseTuple(args, "H", &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_SetString(PyExc_ValueError, + "Message id out of range"); + return (NULL); + } + try { self->message->setQid(id); Py_RETURN_NONE; @@ -565,9 +574,9 @@ 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); } @@ -591,8 +600,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)) { + 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 a00d8d4597..f12001d202 100644 --- a/src/lib/dns/python/messagerenderer_python.cc +++ b/src/lib/dns/python/messagerenderer_python.cc @@ -178,8 +178,16 @@ 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) { + PyErr_SetString(PyExc_ValueError, + "MessageRenderer length limit out of range"); return (NULL); } self->messagerenderer->setLengthLimit(lengthlimit); @@ -190,8 +198,8 @@ static PyObject* MessageRenderer_setCompressMode(s_MessageRenderer* self, PyObject* args) { - unsigned int mode; - if (!PyArg_ParseTuple(args, "I", &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 3d7a1960b9..7d8913a758 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) { + // Throw IndexError here since name index should be unsigned + PyErr_SetString(PyExc_IndexError, + "Name index shouldn't be negative"); + 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)) { + int pos; + if (!PyArg_ParseTuple(args, "i", &pos)) { return (NULL); } + if (pos < 0) { + // Throw IndexError here since name index should be unsigned + PyErr_SetString(PyExc_IndexError, + "name index shouldn't be negative"); + return (NULL); + } + try { return (Py_BuildValue("I", self->name->at(pos))); } catch (const isc::OutOfRange&) { @@ -405,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()); @@ -457,12 +470,18 @@ Name_equals(s_Name* self, PyObject* args) { Py_RETURN_FALSE; } -static PyObject* +static PyObject* Name_split(s_Name* self, PyObject* args) { - unsigned int first, n; + int first, n; s_Name* ret = NULL; - - if (PyArg_ParseTuple(args, "II", &first, &n)) { + + if (PyArg_ParseTuple(args, "ii", &first, &n)) { + 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); if (ret != NULL) { ret->name = NULL; @@ -477,7 +496,14 @@ Name_split(s_Name* self, PyObject* args) { return (NULL); } } - } else if (PyArg_ParseTuple(args, "I", &n)) { + } else if (PyArg_ParseTuple(args, "i", &n)) { + PyErr_Clear(); + 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); if (ret != NULL) { ret->name = NULL; @@ -493,6 +519,10 @@ Name_split(s_Name* self, PyObject* args) { } } } + + PyErr_Clear(); + PyErr_SetString(PyExc_TypeError, + "No valid type in split argument"); return (ret); } #include @@ -502,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/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..b80a93c5d1 100644 --- a/src/lib/dns/python/rcode_python.cc +++ b/src/lib/dns/python/rcode_python.cc @@ -171,18 +171,18 @@ PyTypeObject rcode_type = { int Rcode_init(s_Rcode* const self, PyObject* args) { - int code = 0; + long code = 0; int 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"); + PyErr_SetString(PyExc_ValueError, "Rcode out of range"); return (-1); } ext_code = -1; - } else if (PyArg_ParseTuple(args, "ii", &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"); + 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 3cfed4c045..ca20e68210 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_ValueError, + "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..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,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, "L", &i)) { PyErr_Clear(); + if (i < 0 || i > 0xffffffff) { + PyErr_SetString(PyExc_ValueError, "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..4fc0284771 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_ValueError, "RR Type number out of range"); return (-1); } self->rrtype = new RRType(i); @@ -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 3f03c90068..b249213d7a 100644 --- a/src/lib/dns/python/tests/edns_python_test.py +++ b/src/lib/dns/python/tests/edns_python_test.py @@ -62,17 +62,16 @@ 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. - self.assertRaises(OverflowError, edns.set_udp_size, 65536) - self.assertRaises(OverflowError, edns.set_udp_size, -1) + 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) 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 6ef42d4cd4..bccc5968a3 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,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) - 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) - 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(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") @@ -135,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): @@ -197,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) @@ -239,6 +247,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..53624964bf 100644 --- a/src/lib/dns/python/tests/messagerenderer_python_test.py +++ b/src/lib/dns/python/tests/messagerenderer_python_test.py @@ -98,6 +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) 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..b8e625ab2c 100644 --- a/src/lib/dns/python/tests/name_python_test.py +++ b/src/lib/dns/python/tests/name_python_test.py @@ -95,11 +95,14 @@ class NameTest(unittest.TestCase): b = bytearray() b += b'\x07example'*32 + b'\x03com\x00' self.assertRaises(DNSMessageFORMERR, Name, b, 0) + 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") def test_get_length(self): @@ -151,14 +154,25 @@ 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") - self.assertRaises(IndexError, self.name1.split, 123, 1) - self.assertRaises(IndexError, self.name1.split, 1, 123) 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) + 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(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()) @@ -169,7 +183,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/rcode_python_test.py b/src/lib/dns/python/tests/rcode_python_test.py index 3577f84b5c..77fed3a321 100644 --- a/src/lib/dns/python/tests/rcode_python_test.py +++ b/src/lib/dns/python/tests/rcode_python_test.py @@ -23,12 +23,8 @@ from pydnspp import * class RcodeTest(unittest.TestCase): def test_init(self): self.assertRaises(TypeError, Rcode, "wrong") - self.assertRaises(OverflowError, Rcode, 65536) - 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) @@ -38,7 +34,18 @@ 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(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) + 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 b5e8b5ed9d..38d8c8c34d 100644 --- a/src/lib/dns/python/tests/rrclass_python_test.py +++ b/src/lib/dns/python/tests/rrclass_python_test.py @@ -32,12 +32,17 @@ class RRClassTest(unittest.TestCase): b = bytearray(1) b[0] = 123 self.assertRaises(TypeError, RRClass, b) - self.assertRaises(InvalidRRClass, RRClass, 65536) 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) + 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()) 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 095a0b1964..aa4a34d5aa 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()) @@ -39,7 +39,13 @@ class RRTTLTest(unittest.TestCase): 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()) 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 c35e1e7e78..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(InvalidRRType, 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"); 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); 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. /// 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..5b39dc3218 --- /dev/null +++ b/src/lib/dns/rdata/generic/rp_17.cc @@ -0,0 +1,124 @@ +// 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 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" +/// 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/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 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/buffer_unittest.cc b/src/lib/dns/tests/buffer_unittest.cc index 2fe5a10b17..097391280f 100644 --- a/src/lib/dns/tests/buffer_unittest.cc +++ b/src/lib/dns/tests/buffer_unittest.cc @@ -190,4 +190,53 @@ 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()); + }); +} + +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); + OutputBuffer second(0); + second = first; + }); +} + } 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..52285f17c4 --- /dev/null +++ b/src/lib/dns/tests/rdata_rp_unittest.cc @@ -0,0 +1,162 @@ +// 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 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")); + 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/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: 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 diff --git a/src/lib/resolve/recursive_query.cc b/src/lib/resolve/recursive_query.cc index fedfc71dc8..8ce8ee7912 100644 --- a/src/lib/resolve/recursive_query.cc +++ b/src/lib/resolve/recursive_query.cc @@ -59,19 +59,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 + "(" + @@ -80,6 +80,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 { @@ -225,6 +230,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() @@ -483,7 +492,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), @@ -504,7 +515,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) { @@ -621,9 +633,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); @@ -741,7 +755,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_); } } } @@ -794,7 +809,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 acbb081abf..f63e5fbab6 100644 --- a/src/lib/resolve/recursive_query.h +++ b/src/lib/resolve/recursive_query.h @@ -23,11 +23,41 @@ namespace isc { namespace asiodns { -/// \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 @@ -66,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 @@ -128,6 +166,7 @@ private: int client_timeout_; int lookup_timeout_; unsigned retries_; + boost::shared_ptr rtt_recorder_; ///< Round-trip time recorder }; } // namespace asiodns diff --git a/src/lib/resolve/tests/recursive_query_unittest_2.cc b/src/lib/resolve/tests/recursive_query_unittest_2.cc index 76e37046b8..69215b6bd3 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 @@ -651,13 +652,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_)); @@ -674,6 +679,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 asiodns diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am new file mode 100644 index 0000000000..3e74708405 --- /dev/null +++ b/src/lib/util/Makefile.am @@ -0,0 +1,3 @@ +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/Makefile.am b/src/lib/util/io/Makefile.am new file mode 100644 index 0000000000..b2653d8b34 --- /dev/null +++ b/src/lib/util/io/Makefile.am @@ -0,0 +1,16 @@ +AM_CXXFLAGS = $(B10_CXXFLAGS) + +lib_LTLIBRARIES = libutil_io.la +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/util/io/fd.cc b/src/lib/util/io/fd.cc new file mode 100644 index 0000000000..04e64dcd39 --- /dev/null +++ b/src/lib/util/io/fd.cc @@ -0,0 +1,70 @@ +// 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 "fd.h" + +#include +#include + +namespace isc { +namespace util { +namespace io { + +bool +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) { + 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, 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)); + 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..bdd2d41f58 --- /dev/null +++ b/src/lib/util/io/fd.h @@ -0,0 +1,61 @@ +// 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. + +#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 void *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, void *buffer, const size_t length); + +} +} +} + +#endif // __UTIL_IO_FD_H diff --git a/src/lib/xfr/fd_share.cc b/src/lib/util/io/fd_share.cc similarity index 93% rename from src/lib/xfr/fd_share.cc rename to src/lib/util/io/fd_share.cc index 4e1f0931ad..92576e058e 100644 --- a/src/lib/xfr/fd_share.cc +++ b/src/lib/util/io/fd_share.cc @@ -19,10 +19,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. @@ -86,15 +87,15 @@ recv_fd(const int sock) { msghdr.msg_controllen = cmsg_space(sizeof(int)); msghdr.msg_control = malloc(msghdr.msg_controllen); if (msghdr.msg_control == NULL) { - return (-1); + return (FD_OTHER_ERROR); } if (recvmsg(sock, &msghdr, 0) < 0) { free(msghdr.msg_control); - return (XFR_FD_RECEIVE_FAIL); + return (FD_COMM_ERROR); } const struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msghdr); - int fd = -1; + int fd = FD_OTHER_ERROR; if (cmsg != NULL && cmsg->cmsg_len == cmsg_len(sizeof(int)) && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { fd = *(const int*)CMSG_DATA(cmsg); @@ -119,7 +120,7 @@ send_fd(const int sock, const int fd) { msghdr.msg_controllen = cmsg_space(sizeof(int)); msghdr.msg_control = malloc(msghdr.msg_controllen); if (msghdr.msg_control == NULL) { - return (-1); + return (FD_OTHER_ERROR); } struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msghdr); @@ -130,8 +131,9 @@ send_fd(const int sock, const int fd) { const int ret = sendmsg(sock, &msghdr, 0); free(msghdr.msg_control); - return (ret >= 0 ? 0 : -1); + return (ret >= 0 ? 0 : FD_COMM_ERROR); } -} // End for namespace xfr +} // End for namespace io +} // End for namespace util } // End for namespace isc diff --git a/src/lib/util/io/fd_share.h b/src/lib/util/io/fd_share.h new file mode 100644 index 0000000000..b74d4efaf0 --- /dev/null +++ b/src/lib/util/io/fd_share.h @@ -0,0 +1,65 @@ +// 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. + +#ifndef FD_SHARE_H_ +#define FD_SHARE_H_ + +/** + * \file fd_share.h + * \short Support to transfer file descriptors between processes. + * \todo This interface is very C-ish. Should we have some kind of exceptions? + */ + +namespace isc { +namespace util { +namespace io { + +const int FD_COMM_ERROR = -2; +const int FD_OTHER_ERROR = -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 FD_COMM_ERROR when there's error receiving the socket, FD_OTHER_ERROR + * when there's a different error. + * \param sock The unix domain socket to read from. Tested and it does + * not work with a pipe. + */ +int recv_fd(const int sock); + +/** + * \short Sends a file descriptor. + * This sends a file descriptor over an unix domain socket. This is the + * counterpart of recv_fd(). + * + * \return FD_COMM_ERROR when there's error sending the socket, FD_OTHER_ERROR + * for all other possible errors. + * \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 +} // End for namespace util +} // End for namespace isc + +#endif + +// Local Variables: +// mode: c++ +// End: diff --git a/src/lib/xfr/fdshare_python.cc b/src/lib/util/io/fdshare_python.cc similarity index 70% rename from src/lib/xfr/fdshare_python.cc rename to src/lib/util/io/fdshare_python.cc index 82b1b6e669..0a411073ba 100644 --- a/src/lib/xfr/fdshare_python.cc +++ b/src/lib/util/io/fdshare_python.cc @@ -18,7 +18,7 @@ #include -#include +#include "fd_share.h" static PyObject* @@ -27,7 +27,7 @@ fdshare_recv_fd(PyObject*, 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)); } @@ -37,7 +37,7 @@ fdshare_send_fd(PyObject*, 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)); } @@ -61,20 +61,33 @@ static PyModuleDef bind10_fdshare_python = { }; PyMODINIT_FUNC -PyInit_libxfr_python(void) { - PyObject* mod = PyModule_Create(&bind10_fdshare_python); +PyInit_libutil_io_python(void) { + PyObject *mod = PyModule_Create(&bind10_fdshare_python); if (mod == NULL) { return (NULL); } - PyObject* XFR_FD_RECEIVE_FAIL = Py_BuildValue("i", isc::xfr::XFR_FD_RECEIVE_FAIL); - if (XFR_FD_RECEIVE_FAIL == NULL) { + PyObject* FD_COMM_ERROR = Py_BuildValue("i", isc::util::io::FD_COMM_ERROR); + if (FD_COMM_ERROR == NULL) { Py_XDECREF(mod); return (NULL); } - int ret = PyModule_AddObject(mod, "XFR_FD_RECEIVE_FAIL", XFR_FD_RECEIVE_FAIL); + int ret = PyModule_AddObject(mod, "FD_COMM_ERROR", FD_COMM_ERROR); if (-1 == ret) { - Py_XDECREF(XFR_FD_RECEIVE_FAIL); + Py_XDECREF(FD_COMM_ERROR); + Py_XDECREF(mod); + return (NULL); + } + + PyObject* FD_OTHER_ERROR = Py_BuildValue("i", + isc::util::io::FD_OTHER_ERROR); + if (FD_OTHER_ERROR == NULL) { + Py_XDECREF(mod); + return (NULL); + } + ret = PyModule_AddObject(mod, "FD_OTHER_ERROR", FD_OTHER_ERROR); + if (-1 == ret) { + Py_XDECREF(FD_OTHER_ERROR); Py_XDECREF(mod); return (NULL); } 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..0902ce08b3 --- /dev/null +++ b/src/lib/util/io/tests/fd_share_tests.cc @@ -0,0 +1,74 @@ +// 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 "../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..12b70d8b49 --- /dev/null +++ b/src/lib/util/io/tests/fd_tests.cc @@ -0,0 +1,66 @@ +// 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 "../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..e787ab1cb1 --- /dev/null +++ b/src/lib/util/io/tests/run_unittests.cc @@ -0,0 +1,22 @@ +// 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 + +int +main(int argc, char *argv[]) { + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/src/lib/util/unittests/Makefile.am b/src/lib/util/unittests/Makefile.am new file mode 100644 index 0000000000..0ea86539ff --- /dev/null +++ b/src/lib/util/unittests/Makefile.am @@ -0,0 +1,9 @@ +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 +libutil_unittests_la_LIBADD = \ + $(top_builddir)/src/lib/util/io/libutil_io.la + +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..3414a3c187 --- /dev/null +++ b/src/lib/util/unittests/fork.cc @@ -0,0 +1,145 @@ +// 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 "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; + } + // 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 + 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 void *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 void *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 + close(pipes[0]); + return pid; + } else { + close(pipes[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); + 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)) { + const unsigned char *output_c(static_cast( + output)); + // If they 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_c[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..3331cfabc2 --- /dev/null +++ b/src/lib/util/unittests/fork.h @@ -0,0 +1,52 @@ +// 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. + +#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 void *input, const size_t length); + +pid_t +check_output(int *write_pipe, const void *output, const size_t length); + +} // End of the namespace +} +} + +#endif // __UTIL_UNITTESTS_FORK_H diff --git a/src/lib/xfr/Makefile.am b/src/lib/xfr/Makefile.am index 79cee73cb6..d714990cbf 100644 --- a/src/lib/xfr/Makefile.am +++ b/src/lib/xfr/Makefile.am @@ -2,7 +2,7 @@ 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_CPPFLAGS += $(BOOST_INCLUDES) -AM_CXXFLAGS = $(B10_CXXFLAGS) -Wno-strict-aliasing +AM_CXXFLAGS = $(B10_CXXFLAGS) AM_CXXFLAGS += -Wno-unused-parameter # see src/lib/cc/Makefile.am if USE_CLANGPP AM_CXXFLAGS += -Wno-error @@ -11,13 +11,5 @@ endif 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/fd_share.h b/src/lib/xfr/fd_share.h deleted file mode 100644 index 4ee5fd58bd..0000000000 --- a/src/lib/xfr/fd_share.h +++ /dev/null @@ -1,42 +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. - -#ifndef FD_SHARE_H_ -#define FD_SHARE_H_ - -namespace isc { -namespace xfr { - -/// Failed to receive xfr socket descriptor "fd" on unix domain socket 'sock' -const int XFR_FD_RECEIVE_FAIL = -2; - -// Receive socket descriptor on unix domain socket 'sock'. -// Returned value is the socket descriptor received. -// Returned XFR_FD_RECEIVE_FAIL if failed to receive xfr socket descriptor -// Errors are indicated by a return value of -1. -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. -int send_fd(const int sock, const int fd); - -} // End for namespace xfr -} // End for namespace isc - -#endif - -// Local Variables: -// mode: c++ -// End: diff --git a/src/lib/xfr/xfrout_client.cc b/src/lib/xfr/xfrout_client.cc index e9e736be2d..6ab905b930 100644 --- a/src/lib/xfr/xfrout_client.cc +++ b/src/lib/xfr/xfrout_client.cc @@ -20,10 +20,11 @@ #include #include -#include +#include #include using namespace std; +using namespace isc::util::io; using asio::local::stream_protocol; namespace isc { @@ -72,7 +73,7 @@ XfroutClient::sendXfroutRequestInfo(const int tcp_sock, const void* const msg_data, const uint16_t msg_len) { - if (-1 == send_fd(impl_->socket_.native(), tcp_sock)) { + if (send_fd(impl_->socket_.native(), tcp_sock) < 0) { isc_throw(XfroutError, "Failed to send the socket file descriptor " "to xfrout module"); 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) +# ::=
+#
::= +# +# ::= +# +# ::=
+# ::= +# ::= +# ::= +# ::= { } +# ::= +# ::= | "" +# ::=