BIND 10 trac1113, updated. c293f639684d2c6625b7395c995aa813eafa5fa4 [trac1113] commit minfo wire format testdata
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Aug 11 03:04:30 UTC 2011
The branch, trac1113 has been updated
via c293f639684d2c6625b7395c995aa813eafa5fa4 (commit)
via 00686a614cca93f007335d01c06d78cfd212d973 (commit)
via 5b7dee0548f068e626c0bf5d116fc506d2af92a0 (commit)
via 7990857c32cbb49f4bedf805f86c1b718b3a70d0 (commit)
via 1aa26c98d1b827a80bad8abd7f8bb25c26db72b7 (commit)
via 20483389cb90e4f46486be925b896c8a0438191c (commit)
via 10b192574ca253331298bbc4b05ef70d2cb927d1 (commit)
via 3027ed2010e5e27ef6e8ba519b789269100f442e (commit)
via fc33ec0a47dce3e94fa7179d4d28d7fd050a258d (commit)
via 9a98be99edd71e540bd65631dcbd3d766f93056e (commit)
via 82348d8d9d266d91e570c4ae8d8f1afd3315178a (commit)
via ee2a86bd4c1472e606b3d59ef5c4392b61d7ab48 (commit)
via 0e662967ac5a6c8e187725828cd20b826ca00000 (commit)
via dc979c6874916221df10de3557db0d1b4a19d221 (commit)
via 925045f2ad19d5dccb7dde77530ea16ea7b6341b (commit)
via ba80991049e1e361d2b1de08160c91e5bd38b728 (commit)
via faa90e91384af409419363aca539709e2985708b (commit)
via 1feeca7c2209819dd181f1fbaaa75026d3e38aa2 (commit)
via d7713e5c5033ccb0b51769d7f28d91619655b24d (commit)
via 928dacfdf443393618edf7124a46c599bd760784 (commit)
via b34e7172b5f663faf3add7f6e72a3e2d8ffe680a (commit)
via 7fbc6a734b2a9e33100e57cbea0ce1d20cdf4491 (commit)
via 9f5c36321d6843ba5b2a0e9e6c10c3ffee7b14fc (commit)
via 54ef8963e504e22dcf29405412a95100a210efe5 (commit)
via 98953e35ee95489f01fbe87e55fe91d9571fcb48 (commit)
via f00712037fa4b4cbd0d677d998df3728c0c4d8fe (commit)
via 96249117c97e625ec93d94939e9d75fad18ac2df (commit)
via dfc13c8130787ee07e2386773a221524ac6d802b (commit)
via 6ee994f190d58df863c71389bf9f8edd38d8e3eb (commit)
via f240d7d1d55f4ae87bfd1acc9c07a90870f59a93 (commit)
via 1c5a66507b7dc2990709308979354d8e62646a28 (commit)
via c42eef08cd6cb28c898d46c2168c5c08684d5c36 (commit)
from 5d6fde4aa0d2a93945276dd722be48e05da72faf (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit c293f639684d2c6625b7395c995aa813eafa5fa4
Author: chenzhengzhang <jerry.zzpku at gmail.com>
Date: Thu Aug 11 11:03:33 2011 +0800
[trac1113] commit minfo wire format testdata
commit 00686a614cca93f007335d01c06d78cfd212d973
Author: chenzhengzhang <jerry.zzpku at gmail.com>
Date: Thu Aug 11 11:00:21 2011 +0800
[trac1113] sync with master, fix doxygen and unittest
commit 5b7dee0548f068e626c0bf5d116fc506d2af92a0
Merge: 7990857c32cbb49f4bedf805f86c1b718b3a70d0 1aa26c98d1b827a80bad8abd7f8bb25c26db72b7
Author: chenzhengzhang <jerry.zzpku at gmail.com>
Date: Wed Aug 10 14:30:59 2011 +0800
Merge branch 'master' into trac1113
commit 7990857c32cbb49f4bedf805f86c1b718b3a70d0
Author: chenzhengzhang <jerry.zzpku at gmail.com>
Date: Wed Aug 10 14:30:15 2011 +0800
[trac1113] fix comments
-----------------------------------------------------------------------
Summary of changes:
configure.ac | 7 +-
src/bin/auth/auth_messages.mes | 10 +-
src/bin/auth/tests/testdata/Makefile.am | 2 +-
src/bin/bind10/bind10_messages.mes | 2 +-
src/bin/cmdctl/cmdctl_messages.mes | 2 +-
src/bin/resolver/resolver_messages.mes | 4 +-
src/bin/stats/stats_httpd_messages.mes | 12 +-
src/bin/tests/Makefile.am | 1 +
src/bin/tests/process_rename_test.py.in | 9 +-
src/bin/xfrout/xfrout_messages.mes | 2 +-
src/bin/zonemgr/Makefile.am | 10 +-
src/bin/zonemgr/zonemgr.py.in | 79 +-
src/bin/zonemgr/zonemgr_messages.mes | 145 +++
src/lib/asiodns/asiodns_messages.mes | 10 +-
src/lib/cc/cc_messages.mes | 6 +-
src/lib/dns/rdata/generic/minfo_14.cc | 26 +-
src/lib/dns/rdata/generic/minfo_14.h | 20 +-
src/lib/dns/tests/rdata_minfo_unittest.cc | 109 +--
src/lib/dns/tests/testdata/Makefile.am | 8 +-
src/lib/dns/tests/testdata/gen-wiredata.py.in | 610 ----------
src/lib/dns/tests/testdata/rdata_minfo_fromWire | 55 +-
src/lib/dns/tests/testdata/rdata_minfo_toWire | 15 +
.../testdata/rdata_minfo_toWireUncompressed.spec | 6 +
.../testdata/rdata_minfo_toWireUncompressed.wire | 8 +
src/lib/python/isc/config/ccsession.py | 4 +-
src/lib/python/isc/config/tests/ccsession_test.py | 2 +
src/lib/python/isc/notify/notify_out_messages.mes | 2 +-
src/lib/testutils/testdata/Makefile.am | 2 +-
src/lib/util/Makefile.am | 2 +-
src/lib/util/python/Makefile.am | 1 +
src/lib/util/python/gen_wiredata.py.in | 1211 ++++++++++++++++++++
31 files changed, 1576 insertions(+), 806 deletions(-)
create mode 100644 src/bin/zonemgr/zonemgr_messages.mes
delete mode 100755 src/lib/dns/tests/testdata/gen-wiredata.py.in
create mode 100644 src/lib/dns/tests/testdata/rdata_minfo_toWire
create mode 100644 src/lib/dns/tests/testdata/rdata_minfo_toWireUncompressed.spec
create mode 100644 src/lib/dns/tests/testdata/rdata_minfo_toWireUncompressed.wire
create mode 100644 src/lib/util/python/Makefile.am
create mode 100755 src/lib/util/python/gen_wiredata.py.in
-----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 4ff0d07..6e129b6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.59])
-AC_INIT(bind10-devel, 20110519, bind10-dev at isc.org)
+AC_INIT(bind10-devel, 20110809, bind10-dev at isc.org)
AC_CONFIG_SRCDIR(README)
AM_INIT_AUTOMAKE
AC_CONFIG_HEADERS([config.h])
@@ -873,6 +873,7 @@ AC_CONFIG_FILES([Makefile
src/lib/util/Makefile
src/lib/util/io/Makefile
src/lib/util/unittests/Makefile
+ src/lib/util/python/Makefile
src/lib/util/pyunittests/Makefile
src/lib/util/tests/Makefile
src/lib/acl/Makefile
@@ -932,7 +933,6 @@ AC_OUTPUT([doc/version.ent
src/lib/python/isc/log/tests/log_console.py
src/lib/dns/gen-rdatacode.py
src/lib/python/bind10_config.py
- src/lib/dns/tests/testdata/gen-wiredata.py
src/lib/cc/session_config.h.pre
src/lib/cc/tests/session_unittests_config.h
src/lib/log/tests/console_test.sh
@@ -942,6 +942,7 @@ AC_OUTPUT([doc/version.ent
src/lib/log/tests/severity_test.sh
src/lib/log/tests/tempdir.h
src/lib/util/python/mkpywrapper.py
+ src/lib/util/python/gen_wiredata.py
src/lib/server_common/tests/data_path.h
tests/system/conf.sh
tests/system/glue/setup.sh
@@ -966,13 +967,13 @@ AC_OUTPUT([doc/version.ent
chmod +x src/bin/msgq/run_msgq.sh
chmod +x src/bin/msgq/tests/msgq_test
chmod +x src/lib/dns/gen-rdatacode.py
- chmod +x src/lib/dns/tests/testdata/gen-wiredata.py
chmod +x src/lib/log/tests/console_test.sh
chmod +x src/lib/log/tests/destination_test.sh
chmod +x src/lib/log/tests/init_logger_test.sh
chmod +x src/lib/log/tests/local_file_test.sh
chmod +x src/lib/log/tests/severity_test.sh
chmod +x src/lib/util/python/mkpywrapper.py
+ chmod +x src/lib/util/python/gen_wiredata.py
chmod +x src/lib/python/isc/log/tests/log_console.py
chmod +x tests/system/conf.sh
])
diff --git a/src/bin/auth/auth_messages.mes b/src/bin/auth/auth_messages.mes
index 2bb402c..9f04b76 100644
--- a/src/bin/auth/auth_messages.mes
+++ b/src/bin/auth/auth_messages.mes
@@ -63,7 +63,7 @@ datebase data source, listing the file that is being accessed.
% AUTH_DNS_SERVICES_CREATED DNS services created
This is a debug message indicating that the component that will handling
-incoming queries for the authoritiative server (DNSServices) has been
+incoming queries for the authoritative server (DNSServices) has been
successfully created. It is issued during server startup is an indication
that the initialization is proceeding normally.
@@ -74,7 +74,7 @@ reason for the failure is given in the message.) The server will drop the
packet.
% AUTH_LOAD_TSIG loading TSIG keys
-This is a debug message indicating that the authoritiative server
+This is a debug message indicating that the authoritative server
has requested the keyring holding TSIG keys from the configuration
database. It is issued during server startup is an indication that the
initialization is proceeding normally.
@@ -141,8 +141,8 @@ encountered an internal error whilst processing a received packet:
the cause of the error is included in the message.
The server will return a SERVFAIL error code to the sender of the packet.
-However, this message indicates a potential error in the server.
-Please open a bug ticket for this issue.
+This message indicates a potential error in the server. Please open a
+bug ticket for this issue.
% AUTH_RECEIVED_COMMAND command '%1' received
This is a debug message issued when the authoritative server has received
@@ -209,7 +209,7 @@ channel. It is issued during server startup is an indication that the
initialization is proceeding normally.
% AUTH_STATS_COMMS communication error in sending statistics data: %1
-An error was encountered when the authoritiative server tried to send data
+An error was encountered when the authoritative server tried to send data
to the statistics daemon. The message includes additional information
describing the reason for the failure.
diff --git a/src/bin/auth/tests/testdata/Makefile.am b/src/bin/auth/tests/testdata/Makefile.am
index f6f1f27..c86722f 100644
--- a/src/bin/auth/tests/testdata/Makefile.am
+++ b/src/bin/auth/tests/testdata/Makefile.am
@@ -23,4 +23,4 @@ EXTRA_DIST += example.com
EXTRA_DIST += example.sqlite3
.spec.wire:
- $(abs_top_builddir)/src/lib/dns/tests/testdata/gen-wiredata.py -o $@ $<
+ $(PYTHON) $(top_builddir)/src/lib/util/python/gen_wiredata.py -o $@ $<
diff --git a/src/bin/bind10/bind10_messages.mes b/src/bin/bind10/bind10_messages.mes
index e10bc7c..4bac069 100644
--- a/src/bin/bind10/bind10_messages.mes
+++ b/src/bin/bind10/bind10_messages.mes
@@ -122,7 +122,7 @@ The boss requested a socket from the creator, but the answer is unknown. This
looks like a programmer error.
% BIND10_SOCKCREATOR_CRASHED the socket creator crashed
-The socket creator terminated unexpectadly. It is not possible to restart it
+The socket creator terminated unexpectedly. It is not possible to restart it
(because the boss already gave up root privileges), so the system is going
to terminate.
diff --git a/src/bin/cmdctl/cmdctl_messages.mes b/src/bin/cmdctl/cmdctl_messages.mes
index 55b941f..e007296 100644
--- a/src/bin/cmdctl/cmdctl_messages.mes
+++ b/src/bin/cmdctl/cmdctl_messages.mes
@@ -69,7 +69,7 @@ There was a keyboard interrupt signal to stop the cmdctl daemon. The
daemon will now shut down.
% CMDCTL_UNCAUGHT_EXCEPTION uncaught exception: %1
-The b10-cdmctl daemon encountered an uncaught exception and
+The b10-cmdctl daemon encountered an uncaught exception and
will now shut down. This is indicative of a programming error and
should not happen under normal circumstances. The exception message
is printed.
diff --git a/src/bin/resolver/resolver_messages.mes b/src/bin/resolver/resolver_messages.mes
index b44115a..7930c52 100644
--- a/src/bin/resolver/resolver_messages.mes
+++ b/src/bin/resolver/resolver_messages.mes
@@ -78,7 +78,7 @@ specified, it will appear once for each address.
% RESOLVER_FORWARD_QUERY processing forward query
This is a debug message indicating that a query received by the resolver
has passed a set of checks (message is well-formed, it is allowed by the
-ACL, it is a supported opcode etc.) and is being forwarded to upstream
+ACL, it is a supported opcode, etc.) and is being forwarded to upstream
servers.
% RESOLVER_HEADER_ERROR message received, exception when processing header: %1
@@ -116,7 +116,7 @@ so is returning a REFUSED response to the sender.
% RESOLVER_NORMAL_QUERY processing normal query
This is a debug message indicating that the query received by the resolver
has passed a set of checks (message is well-formed, it is allowed by the
-ACL, it is a supported opcode etc.) and is being processed the resolver.
+ACL, it is a supported opcode, etc.) and is being processed by the resolver.
% RESOLVER_NOTIFY_RECEIVED NOTIFY arrived but server is not authoritative
The resolver has received a NOTIFY message. As the server is not
diff --git a/src/bin/stats/stats_httpd_messages.mes b/src/bin/stats/stats_httpd_messages.mes
index d0f7e2c..0e984dc 100644
--- a/src/bin/stats/stats_httpd_messages.mes
+++ b/src/bin/stats/stats_httpd_messages.mes
@@ -49,14 +49,14 @@ An unknown command has been sent to the stats-httpd module. The
stats-httpd module will respond with an error, and the command will
be ignored.
-% STATHTTPD_SERVER_ERROR http server error: %1
-An internal error occurred while handling an http request. A HTTP 500
+% STATHTTPD_SERVER_ERROR HTTP server error: %1
+An internal error occurred while handling an HTTP request. An HTTP 500
response will be sent back, and the specific error is printed. This
is an error condition that likely points to a module that is not
responding correctly to statistic requests.
-% STATHTTPD_SERVER_INIT_ERROR http server initialization error: %1
-There was a problem initializing the http server in the stats-httpd
+% STATHTTPD_SERVER_INIT_ERROR HTTP server initialization error: %1
+There was a problem initializing the HTTP server in the stats-httpd
module upon receiving its configuration data. The most likely cause
is a port binding problem or a bad configuration value. The specific
error is printed in the message. The new configuration is ignored,
@@ -65,8 +65,8 @@ and an error is sent back.
% STATHTTPD_SHUTDOWN shutting down
The stats-httpd daemon is shutting down.
-% STATHTTPD_START_SERVER_INIT_ERROR http server initialization error: %1
-There was a problem initializing the http server in the stats-httpd
+% STATHTTPD_START_SERVER_INIT_ERROR HTTP server initialization error: %1
+There was a problem initializing the HTTP server in the stats-httpd
module upon startup. The most likely cause is that it was not able
to bind to the listening port. The specific error is printed, and the
module will shut down.
diff --git a/src/bin/tests/Makefile.am b/src/bin/tests/Makefile.am
index b5bcea2..56ff68b 100644
--- a/src/bin/tests/Makefile.am
+++ b/src/bin/tests/Makefile.am
@@ -1,5 +1,6 @@
PYCOVERAGE_RUN = @PYCOVERAGE_RUN@
PYTESTS = process_rename_test.py
+noinst_SCRIPTS = $(PYTESTS)
# .py will be generated by configure, so we don't have to include it
# in EXTRA_DIST.
diff --git a/src/bin/tests/process_rename_test.py.in b/src/bin/tests/process_rename_test.py.in
index 4b45210..f96c023 100644
--- a/src/bin/tests/process_rename_test.py.in
+++ b/src/bin/tests/process_rename_test.py.in
@@ -38,8 +38,10 @@ class TestRename(unittest.TestCase):
Then scan them by looking at the source text
(without actually running them)
"""
- # Regexp to find all the *_SCRIPTS = something lines,
- # including line continuations (backslash and newline)
+ # Regexp to find all the *_SCRIPTS = something lines (except for
+ # noinst_SCRIPTS, which are scripts for tests), including line
+ # continuations (backslash and newline)
+ excluded_lines = re.compile(r'^(noinst_SCRIPTS.*$)', re.MULTILINE)
lines = re.compile(r'^\w+_SCRIPTS\s*=\s*((.|\\\n)*)$',
re.MULTILINE)
# Script name regular expression
@@ -53,7 +55,8 @@ class TestRename(unittest.TestCase):
if 'Makefile' in fs:
makefile = ''.join(open(os.path.join(d,
"Makefile")).readlines())
- for (var, _) in lines.findall(makefile):
+ for (var, _) in lines.findall(re.sub(excluded_lines, '',
+ makefile)):
for (script, _) in scripts.findall(var):
self.__scan(d, script, fun)
diff --git a/src/bin/xfrout/xfrout_messages.mes b/src/bin/xfrout/xfrout_messages.mes
index 19b104e..121b2ad 100644
--- a/src/bin/xfrout/xfrout_messages.mes
+++ b/src/bin/xfrout/xfrout_messages.mes
@@ -48,7 +48,7 @@ There was a problem reading from the command and control channel. The
most likely cause is that the msgq daemon is not running.
% XFROUT_CC_SESSION_TIMEOUT_ERROR timeout waiting for cc response
-There was a problem reading a response from antoher module over the
+There was a problem reading a response from another module over the
command and control channel. The most likely cause is that the
configuration manager b10-cfgmgr is not running.
diff --git a/src/bin/zonemgr/Makefile.am b/src/bin/zonemgr/Makefile.am
index 8ab5f7a..34e6622 100644
--- a/src/bin/zonemgr/Makefile.am
+++ b/src/bin/zonemgr/Makefile.am
@@ -6,11 +6,13 @@ pkglibexec_SCRIPTS = b10-zonemgr
b10_zonemgrdir = $(pkgdatadir)
b10_zonemgr_DATA = zonemgr.spec
+pyexec_DATA = zonemgr_messages.py
-CLEANFILES = b10-zonemgr zonemgr.pyc zonemgr.spec
+CLEANFILES = b10-zonemgr zonemgr.pyc zonemgr.spec
+CLEANFILES += zonemgr_messages.py zonemgr_messages.pyc
man_MANS = b10-zonemgr.8
-EXTRA_DIST = $(man_MANS) b10-zonemgr.xml
+EXTRA_DIST = $(man_MANS) b10-zonemgr.xml zonemgr_messages.mes
if ENABLE_MAN
@@ -19,6 +21,10 @@ b10-zonemgr.8: b10-zonemgr.xml
endif
+# Build logging source file from message files
+zonemgr_messages.py: zonemgr_messages.mes
+ $(top_builddir)/src/lib/log/compiler/message -p $(top_srcdir)/src/bin/zonemgr/zonemgr_messages.mes
+
zonemgr.spec: zonemgr.spec.pre
$(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" zonemgr.spec.pre >$@
diff --git a/src/bin/zonemgr/zonemgr.py.in b/src/bin/zonemgr/zonemgr.py.in
index 845190b..87a0092 100755
--- a/src/bin/zonemgr/zonemgr.py.in
+++ b/src/bin/zonemgr/zonemgr.py.in
@@ -37,10 +37,16 @@ from isc.datasrc import sqlite3_ds
from optparse import OptionParser, OptionValueError
from isc.config.ccsession import *
import isc.util.process
+from zonemgr_messages import *
# Initialize logging for called modules.
-# TODO: Log messages properly
isc.log.init("b10-zonemgr")
+logger = isc.log.Logger("zonemgr")
+
+# Constants for debug levels, to be removed when we have #1074.
+DBG_START_SHUT = 0
+DBG_ZONEMGR_COMMAND = 10
+DBG_ZONEMGR_BASIC = 40
isc.util.process.rename()
@@ -81,13 +87,6 @@ REFRESH_OFFSET = 3
RETRY_OFFSET = 4
EXPIRED_OFFSET = 5
-# verbose mode
-VERBOSE_MODE = False
-
-def log_msg(msg):
- if VERBOSE_MODE:
- sys.stdout.write("[b10-zonemgr] %s\n" % str(msg))
-
class ZonemgrException(Exception):
pass
@@ -97,7 +96,6 @@ class ZonemgrRefresh:
do zone refresh.
Zone timers can be started by calling run_timer(), and it
can be stopped by calling shutdown() in another thread.
-
"""
def __init__(self, cc, db_file, slave_socket, config_data):
@@ -161,6 +159,7 @@ class ZonemgrRefresh:
def zone_refresh_success(self, zone_name_class):
"""Update zone info after zone refresh success"""
if (self._zone_not_exist(zone_name_class)):
+ logger.error(ZONEMGR_UNKNOWN_ZONE_SUCCESS, zone_name_class[0], zone_name_class[1])
raise ZonemgrException("[b10-zonemgr] Zone (%s, %s) doesn't "
"belong to zonemgr" % zone_name_class)
self.zonemgr_reload_zone(zone_name_class)
@@ -171,6 +170,7 @@ class ZonemgrRefresh:
def zone_refresh_fail(self, zone_name_class):
"""Update zone info after zone refresh fail"""
if (self._zone_not_exist(zone_name_class)):
+ logger.error(ZONEMGR_UNKNOWN_ZONE_FAIL, zone_name_class[0], zone_name_class[1])
raise ZonemgrException("[b10-zonemgr] Zone (%s, %s) doesn't "
"belong to zonemgr" % zone_name_class)
# Is zone expired?
@@ -183,6 +183,7 @@ class ZonemgrRefresh:
def zone_handle_notify(self, zone_name_class, master):
"""Handle zone notify"""
if (self._zone_not_exist(zone_name_class)):
+ logger.error(ZONEMGR_UNKNOWN_ZONE_NOTIFIED, zone_name_class[0], zone_name_class[1])
raise ZonemgrException("[b10-zonemgr] Notified zone (%s, %s) "
"doesn't belong to zonemgr" % zone_name_class)
self._set_zone_notifier_master(zone_name_class, master)
@@ -195,10 +196,12 @@ class ZonemgrRefresh:
def zonemgr_add_zone(self, zone_name_class):
""" Add a zone into zone manager."""
- log_msg("Loading zone (%s, %s)" % zone_name_class)
+
+ logger.debug(DBG_ZONEMGR_BASIC, ZONEMGR_LOAD_ZONE, zone_name_class[0], zone_name_class[1])
zone_info = {}
zone_soa = sqlite3_ds.get_zone_soa(str(zone_name_class[0]), self._db_file)
if not zone_soa:
+ logger.error(ZONEMGR_NO_SOA, zone_name_class[0], zone_name_class[1])
raise ZonemgrException("[b10-zonemgr] zone (%s, %s) doesn't have soa." % zone_name_class)
zone_info["zone_soa_rdata"] = zone_soa[7]
zone_info["zone_state"] = ZONE_OK
@@ -269,7 +272,7 @@ class ZonemgrRefresh:
except isc.cc.session.SessionTimeout:
pass # for now we just ignore the failure
except socket.error:
- sys.stderr.write("[b10-zonemgr] Failed to send to module %s, the session has been closed." % module_name)
+ logger.error(ZONEMGR_SEND_FAIL, module_name)
def _find_need_do_refresh_zone(self):
"""Find the first zone need do refresh, if no zone need
@@ -278,7 +281,8 @@ class ZonemgrRefresh:
zone_need_refresh = None
for zone_name_class in self._zonemgr_refresh_info.keys():
zone_state = self._get_zone_state(zone_name_class)
- # If hasn't received refresh response but are within refresh timeout, skip the zone
+ # If hasn't received refresh response but are within refresh
+ # timeout, skip the zone
if (ZONE_REFRESHING == zone_state and
(self._get_zone_refresh_timeout(zone_name_class) > self._get_current_time())):
continue
@@ -298,7 +302,7 @@ class ZonemgrRefresh:
def _do_refresh(self, zone_name_class):
"""Do zone refresh."""
- log_msg("Do refresh for zone (%s, %s)." % zone_name_class)
+ logger.debug(DBG_ZONEMGR_BASIC, ZONEMGR_REFRESH_ZONE, zone_name_class[0], zone_name_class[1])
self._set_zone_state(zone_name_class, ZONE_REFRESHING)
self._set_zone_refresh_timeout(zone_name_class, self._get_current_time() + self._max_transfer_timeout)
notify_master = self._get_zone_notifier_master(zone_name_class)
@@ -355,7 +359,7 @@ class ZonemgrRefresh:
if e.args[0] == errno.EINTR:
(rlist, wlist, xlist) = ([], [], [])
else:
- sys.stderr.write("[b10-zonemgr] Error with select(); %s\n" % e)
+ logger.error(ZONEMGR_SELECT_ERROR, e);
break
for fd in rlist:
@@ -369,12 +373,14 @@ class ZonemgrRefresh:
def run_timer(self, daemon=False):
"""
- Keep track of zone timers. Spawns and starts a thread. The thread object is returned.
+ Keep track of zone timers. Spawns and starts a thread. The thread object
+ is returned.
You can stop it by calling shutdown().
"""
# Small sanity check
if self._running:
+ logger.error(ZONEMGR_TIMER_THREAD_RUNNING)
raise RuntimeError("Trying to run the timers twice at the same time")
# Prepare the launch
@@ -399,6 +405,7 @@ class ZonemgrRefresh:
called from a different thread.
"""
if not self._running:
+ logger.error(ZONEMGR_NO_TIMER_THREAD)
raise RuntimeError("Trying to shutdown, but not running")
# Ask the thread to stop
@@ -519,8 +526,8 @@ class Zonemgr:
return db_file
def shutdown(self):
- """Shutdown the zonemgr process. the thread which is keeping track of zone
- timers should be terminated.
+ """Shutdown the zonemgr process. The thread which is keeping track of
+ zone timers should be terminated.
"""
self._zone_refresh.shutdown()
@@ -560,17 +567,17 @@ class Zonemgr:
# jitter should not be bigger than half of the original value
if config_data.get('refresh_jitter') > 0.5:
config_data['refresh_jitter'] = 0.5
- log_msg("[b10-zonemgr] refresh_jitter is too big, its value will "
- "be set to 0.5")
-
+ logger.warn(ZONEMGR_JITTER_TOO_BIG)
def _parse_cmd_params(self, args, command):
zone_name = args.get("zone_name")
if not zone_name:
+ logger.error(ZONEMGR_NO_ZONE_NAME)
raise ZonemgrException("zone name should be provided")
zone_class = args.get("zone_class")
if not zone_class:
+ logger.error(ZONEMGR_NO_ZONE_CLASS)
raise ZonemgrException("zone class should be provided")
if (command != ZONE_NOTIFY_COMMAND):
@@ -578,6 +585,7 @@ class Zonemgr:
master_str = args.get("master")
if not master_str:
+ logger.error(ZONEMGR_NO_MASTER_ADDRESS)
raise ZonemgrException("master address should be provided")
return ((zone_name, zone_class), master_str)
@@ -585,15 +593,16 @@ class Zonemgr:
def command_handler(self, command, args):
"""Handle command receivd from command channel.
- ZONE_NOTIFY_COMMAND is issued by Auth process; ZONE_XFRIN_SUCCESS_COMMAND
- and ZONE_XFRIN_FAILED_COMMAND are issued by Xfrin process; shutdown is issued
- by a user or Boss process. """
+ ZONE_NOTIFY_COMMAND is issued by Auth process;
+ ZONE_XFRIN_SUCCESS_COMMAND and ZONE_XFRIN_FAILED_COMMAND are issued by
+ Xfrin process;
+ shutdown is issued by a user or Boss process. """
answer = create_answer(0)
if command == ZONE_NOTIFY_COMMAND:
""" Handle Auth notify command"""
# master is the source sender of the notify message.
zone_name_class, master = self._parse_cmd_params(args, command)
- log_msg("Received notify command for zone (%s, %s)." % zone_name_class)
+ logger.debug(DBG_ZONEMGR_COMMAND, ZONEMGR_RECEIVE_NOTIFY, zone_name_class[0], zone_name_class[1])
with self._lock:
self._zone_refresh.zone_handle_notify(zone_name_class, master)
# Send notification to zonemgr timer thread
@@ -602,6 +611,7 @@ class Zonemgr:
elif command == ZONE_XFRIN_SUCCESS_COMMAND:
""" Handle xfrin success command"""
zone_name_class = self._parse_cmd_params(args, command)
+ logger.debug(DBG_ZONEMGR_COMMAND, ZONEMGR_RECEIVE_XFRIN_SUCCESS, zone_name_class[0], zone_name_class[1])
with self._lock:
self._zone_refresh.zone_refresh_success(zone_name_class)
self._master_socket.send(b" ")# make self._slave_socket readble
@@ -609,14 +619,17 @@ class Zonemgr:
elif command == ZONE_XFRIN_FAILED_COMMAND:
""" Handle xfrin fail command"""
zone_name_class = self._parse_cmd_params(args, command)
+ logger.debug(DBG_ZONEMGR_COMMAND, ZONEMGR_RECEIVE_XFRIN_FAILED, zone_name_class[0], zone_name_class[1])
with self._lock:
self._zone_refresh.zone_refresh_fail(zone_name_class)
self._master_socket.send(b" ")# make self._slave_socket readble
elif command == "shutdown":
+ logger.debug(DBG_ZONEMGR_COMMAND, ZONEMGR_RECEIVE_SHUTDOWN)
self.shutdown()
else:
+ logger.warn(ZONEMGR_RECEIVE_UNKNOWN, str(command))
answer = create_answer(1, "Unknown command:" + str(command))
return answer
@@ -643,25 +656,29 @@ def set_cmd_options(parser):
if '__main__' == __name__:
try:
+ logger.debug(DBG_START_SHUT, ZONEMGR_STARTING)
parser = OptionParser()
set_cmd_options(parser)
(options, args) = parser.parse_args()
- VERBOSE_MODE = options.verbose
+ if options.verbose:
+ logger.set_severity("DEBUG", 99)
set_signal_handler()
zonemgrd = Zonemgr()
zonemgrd.run()
except KeyboardInterrupt:
- sys.stderr.write("[b10-zonemgr] exit zonemgr process\n")
+ logger.info(ZONEMGR_KEYBOARD_INTERRUPT)
+
except isc.cc.session.SessionError as e:
- sys.stderr.write("[b10-zonemgr] Error creating zonemgr, "
- "is the command channel daemon running?\n")
+ logger.error(ZONEMGR_SESSION_ERROR)
+
except isc.cc.session.SessionTimeout as e:
- sys.stderr.write("[b10-zonemgr] Error creating zonemgr, "
- "is the configuration manager running?\n")
+ logger.error(ZONEMGR_SESSION_TIMEOUT)
+
except isc.config.ModuleCCSessionError as e:
- sys.stderr.write("[b10-zonemgr] exit zonemgr process: %s\n" % str(e))
+ logger.error(ZONEMGR_CCSESSION_ERROR, str(e))
if zonemgrd and zonemgrd.running:
zonemgrd.shutdown()
+ logger.debug(DBG_START_SHUT, ZONEMGR_SHUTDOWN)
diff --git a/src/bin/zonemgr/zonemgr_messages.mes b/src/bin/zonemgr/zonemgr_messages.mes
new file mode 100644
index 0000000..8abec5d
--- /dev/null
+++ b/src/bin/zonemgr/zonemgr_messages.mes
@@ -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.
+
+# No namespace declaration - these constants go in the global namespace
+# of the zonemgr messages python module.
+
+% ZONEMGR_CCSESSION_ERROR command channel session error: %1
+An error was encountered on the command channel. The message indicates
+the nature of the error.
+
+% ZONEMGR_JITTER_TOO_BIG refresh_jitter is too big, setting to 0.5
+The value specified in the configuration for the refresh jitter is too large
+so its value has been set to the maximum of 0.5.
+
+% ZONEMGR_KEYBOARD_INTERRUPT exiting zonemgr process as result of keyboard interrupt
+An informational message output when the zone manager was being run at a
+terminal and it was terminated via a keyboard interrupt signal.
+
+% ZONEMGR_LOAD_ZONE loading zone %1 (class %2)
+This is a debug message indicating that the zone of the specified class
+is being loaded.
+
+% ZONEMGR_NO_MASTER_ADDRESS internal BIND 10 command did not contain address of master
+A command received by the zone manager from the Auth module did not
+contain the address of the master server from which a NOTIFY message
+was received. This may be due to an internal programming error; please
+submit a bug report.
+
+% ZONEMGR_NO_SOA zone %1 (class %2) does not have an SOA record
+When loading the named zone of the specified class the zone manager
+discovered that the data did not contain an SOA record. The load has
+been abandoned.
+
+% ZONEMGR_NO_TIMER_THREAD trying to stop zone timer thread but it is not running
+An attempt was made to stop the timer thread (used to track when zones
+should be refreshed) but it was not running. This may indicate an
+internal program error. Please submit a bug report.
+
+% ZONEMGR_NO_ZONE_CLASS internal BIND 10 command did not contain class of zone
+A command received by the zone manager from another BIND 10 module did
+not contain the class of the zone on which the zone manager should act.
+This may be due to an internal programming error; please submit a
+bug report.
+
+% ZONEMGR_NO_ZONE_NAME internal BIND 10 command did not contain name of zone
+A command received by the zone manager from another BIND 10 module did
+not contain the name of the zone on which the zone manager should act.
+This may be due to an internal programming error; please submit a
+bug report.
+
+% ZONEMGR_RECEIVE_NOTIFY received NOTIFY command for zone %1 (class %2)
+This is a debug message indicating that the zone manager has received a
+NOTIFY command over the command channel. The command is sent by the Auth
+process when it is acting as a slave server for the zone and causes the
+zone manager to record the master server for the zone and start a timer;
+when the timer expires, the master will be polled to see if it contains
+new data.
+
+% ZONEMGR_RECEIVE_SHUTDOWN received SHUTDOWN command
+This is a debug message indicating that the zone manager has received
+a SHUTDOWN command over the command channel from the Boss process.
+It will act on this command and shut down.
+
+% ZONEMGR_RECEIVE_UNKNOWN received unknown command '%1'
+This is a warning message indicating that the zone manager has received
+the stated command over the command channel. The command is not known
+to the zone manager and although the command is ignored, its receipt
+may indicate an internal error. Please submit a bug report.
+
+% ZONEMGR_RECEIVE_XFRIN_FAILED received XFRIN FAILED command for zone %1 (class %2)
+This is a debug message indicating that the zone manager has received
+an XFRIN FAILED command over the command channel. The command is sent
+by the Xfrin process when a transfer of zone data into the system has
+failed, and causes the zone manager to schedule another transfer attempt.
+
+% ZONEMGR_RECEIVE_XFRIN_SUCCESS received XFRIN SUCCESS command for zone %1 (class %2)
+This is a debug message indicating that the zone manager has received
+an XFRIN SUCCESS command over the command channel. The command is sent
+by the Xfrin process when the transfer of zone data into the system has
+succeeded, and causes the data to be loaded and served by BIND 10.
+
+% ZONEMGR_REFRESH_ZONE refreshing zone %1 (class %2)
+The zone manager is refreshing the named zone of the specified class
+with updated information.
+
+% ZONEMGR_SELECT_ERROR error with select(): %1
+An attempt to wait for input from a socket failed. The failing operation
+is a call to the operating system's select() function, which failed for
+the given reason.
+
+% ZONEMGR_SEND_FAIL failed to send command to %1, session has been closed
+The zone manager attempted to send a command to the named BIND 10 module,
+but the send failed. The session between the modules has been closed.
+
+% ZONEMGR_SESSION_ERROR unable to establish session to command channel daemon
+The zonemgr process was not able to be started because it could not
+connect to the command channel daemon. The most usual cause of this
+problem is that the daemon is not running.
+
+% ZONEMGR_SESSION_TIMEOUT timeout on session to command channel daemon
+The zonemgr process was not able to be started because it timed out when
+connecting to the command channel daemon. The most usual cause of this
+problem is that the daemon is not running.
+
+% ZONEMGR_SHUTDOWN zone manager has shut down
+A debug message, output when the zone manager has shut down completely.
+
+% ZONEMGR_STARTING zone manager starting
+A debug message output when the zone manager starts up.
+
+% ZONEMGR_TIMER_THREAD_RUNNING trying to start timer thread but one is already running
+This message is issued when an attempt is made to start the timer
+thread (which keeps track of when zones need a refresh) but one is
+already running. It indicates either an error in the program logic or
+a problem with stopping a previous instance of the timer. Please submit
+a bug report.
+
+% ZONEMGR_UNKNOWN_ZONE_FAIL zone %1 (class %2) is not known to the zone manager
+An XFRIN operation has failed but the zone that was the subject of the
+operation is not being managed by the zone manager. This may indicate
+an error in the program (as the operation should not have been initiated
+if this were the case). Please submit a bug report.
+
+% ZONEMGR_UNKNOWN_ZONE_NOTIFIED notified zone %1 (class %2) is not known to the zone manager
+A NOTIFY was received but the zone that was the subject of the operation
+is not being managed by the zone manager. This may indicate an error
+in the program (as the operation should not have been initiated if this
+were the case). Please submit a bug report.
+
+% ZONEMGR_UNKNOWN_ZONE_SUCCESS zone %1 (class %2) is not known to the zone manager
+An XFRIN operation has succeeded but the zone received is not being
+managed by the zone manager. This may indicate an error in the program
+(as the operation should not have been initiated if this were the case).
+Please submit a bug report.
diff --git a/src/lib/asiodns/asiodns_messages.mes b/src/lib/asiodns/asiodns_messages.mes
index 3e11ede..feb75d4 100644
--- a/src/lib/asiodns/asiodns_messages.mes
+++ b/src/lib/asiodns/asiodns_messages.mes
@@ -26,13 +26,13 @@ enabled.
% ASIODNS_OPEN_SOCKET error %1 opening %2 socket to %3(%4)
The asynchronous I/O code encountered an error when trying to open a socket
of the specified protocol in order to send a message to the target address.
-The number of the system error that cause the problem is given in the
+The number of the system error that caused the problem is given in the
message.
% ASIODNS_READ_DATA error %1 reading %2 data from %3(%4)
The asynchronous I/O code encountered an error when trying to read data from
the specified address on the given protocol. The number of the system
-error that cause the problem is given in the message.
+error that caused the problem is given in the message.
% ASIODNS_READ_TIMEOUT receive timeout while waiting for data from %1(%2)
An upstream fetch from the specified address timed out. This may happen for
@@ -41,9 +41,9 @@ or a problem on the network. The message will only appear if debug is
enabled.
% ASIODNS_SEND_DATA error %1 sending data using %2 to %3(%4)
-The asynchronous I/O code encountered an error when trying send data to
-the specified address on the given protocol. The the number of the system
-error that cause the problem is given in the message.
+The asynchronous I/O code encountered an error when trying to send data to
+the specified address on the given protocol. The number of the system
+error that caused the problem is given in the message.
% ASIODNS_UNKNOWN_ORIGIN unknown origin for ASIO error code %1 (protocol: %2, address %3)
An internal consistency check on the origin of a message from the
diff --git a/src/lib/cc/cc_messages.mes b/src/lib/cc/cc_messages.mes
index 8c62ea1..8370cdd 100644
--- a/src/lib/cc/cc_messages.mes
+++ b/src/lib/cc/cc_messages.mes
@@ -53,11 +53,11 @@ Debug message, we're about to send a message over the command channel.
This happens when garbage comes over the command channel or some kind of
confusion happens in the program. The data received from the socket make no
sense if we interpret it as lengths of message. The first one is total length
-of message, the second length of the header. The header and it's length
-(2 bytes) is counted in the total length.
+of the message; the second is the length of the header. The header
+and its length (2 bytes) is counted in the total length.
% CC_LENGTH_NOT_READY length not ready
-There should be data representing length of message on the socket, but it
+There should be data representing the length of message on the socket, but it
is not there.
% CC_NO_MESSAGE no message ready to be received yet
diff --git a/src/lib/dns/rdata/generic/minfo_14.cc b/src/lib/dns/rdata/generic/minfo_14.cc
index d7a8c13..072c767 100644
--- a/src/lib/dns/rdata/generic/minfo_14.cc
+++ b/src/lib/dns/rdata/generic/minfo_14.cc
@@ -40,12 +40,11 @@ using namespace isc::dns;
///
/// <b>Exceptions</b>
///
-/// If <rmailbox name> or <emailbox name> if not a valid domain name, a
-/// corresponding exception from the \c Name class will be thrown;
-/// If the number of RDATA fields (must be 2) is incorrect, an exception of
-/// class \c InvalidRdataText will be thrown.
-/// This constructor internally involves resource allocation, and if it
-/// fails a corresponding standard exception std::bad_alloc will be throw.
+/// \exception InvalidRdataText The number of RDATA fields (must be 2) is
+/// incorrect.
+/// \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 string is invalid.
MINFO::MINFO(const std::string& minfo_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
@@ -96,8 +95,7 @@ MINFO::MINFO(const MINFO& other) :
/// The output of this method is formatted as described in the "from string"
/// constructor (\c MINFO(const std::string&))).
///
-/// If internal resource allocation fails, a corresponding
-/// standard exception will be thrown.
+/// \exception std::bad_alloc Internal resource allocation fails.
///
/// \return A \c string object that represents the \c MINFO object.
std::string
@@ -107,9 +105,7 @@ MINFO::toText() const {
/// \brief Render the \c MINFO in the wire format without name compression.
///
-/// If internal resource allocation fails, a corresponding standard
-/// exception will be thrown.
-/// This method never throws an exception otherwise.
+/// \exception std::bad_alloc Internal resource allocation fails.
///
/// \param buffer An output buffer to store the wire data.
void
@@ -121,12 +117,10 @@ MINFO::toWire(OutputBuffer& buffer) const {
/// \brief Render the \c MINFO in the wire format with taking into account
/// compression.
///
-/// As specified in RFC1035, the rmailbox and emailbox fields (domain names)
-/// will be compressed.
+/// As specified in RFC3597, TYPE MINFO is "well-known", the rmailbox and
+/// emailbox fields (domain names) will be compressed.
///
-/// If internal resource allocation fails, a corresponding
-/// standard exception will be thrown.
-/// This method never throws an exception otherwise.
+/// \exception std::bad_alloc Internal resource allocation fails.
///
/// \param renderer DNS message rendering context that encapsulates the
/// output buffer and name compression information.
diff --git a/src/lib/dns/rdata/generic/minfo_14.h b/src/lib/dns/rdata/generic/minfo_14.h
index 9a1120a..f93f619 100644
--- a/src/lib/dns/rdata/generic/minfo_14.h
+++ b/src/lib/dns/rdata/generic/minfo_14.h
@@ -37,21 +37,10 @@ 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 %MINFO RDATA
- /// fields as defined in RFC1035.
- MINFO(const Name& rmailbox, const Name& emailbox) :
- rmailbox_(rmailbox), emailbox_(emailbox)
- {}
-
/// \brief Return the value of the rmailbox 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.
+ /// \exception std::bad_alloc If resource allocation for the returned
+ /// \c Name fails.
///
/// \note
/// Unlike the case of some other RDATA classes (such as
@@ -69,9 +58,8 @@ public:
/// \brief Return the value of the emailbox 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.
+ /// \exception std::bad_alloc If resource allocation for the returned
+ /// \c Name fails.
Name getEmailbox() const { return (emailbox_); }
private:
diff --git a/src/lib/dns/tests/rdata_minfo_unittest.cc b/src/lib/dns/tests/rdata_minfo_unittest.cc
index 99945c6..b700968 100644
--- a/src/lib/dns/tests/rdata_minfo_unittest.cc
+++ b/src/lib/dns/tests/rdata_minfo_unittest.cc
@@ -37,107 +37,80 @@ class Rdata_MINFO_Test : public RdataTest {
};
// minfo text
-string minfo_txt("root.example.com. emailbx.example.com.");
-string minfo_txt2("rmailbx.example.com. emailbx.example.com.");
-string too_long_label("012345678901234567890123456789"
- "0123456789012345678901234567890123");
-
-// root.example.com. emailbx.example.com.
-const uint8_t uncompressed_wiredata_minfo[] = {
- 0x04, 0x72, 0x6f, 0x6f, 0x74, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70,
- 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x07, 0x65, 0x6d, 0x61,
- 0x69, 0x6c, 0x62, 0x78, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c,
- 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00};
-// rmailbx.example.com. emailbx.example.com.
-const uint8_t uncompressed_wiredata_minfo2[] = {
- 0x07, 0x72, 0x6d, 0x61, 0x69, 0x6c, 0x62, 0x78, 0x07, 0x65, 0x78,
- 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x07,
- 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x62, 0x78, 0x07, 0x65, 0x78, 0x61,
- 0x6d, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00};
-
-// root.example.com. emailbx.example.com.
-const uint8_t compressed_wiredata_minfo[] = {
- 0x04, 0x72, 0x6f, 0x6f, 0x74, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70,
- 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x07, 0x65, 0x6d, 0x61,
- 0x69, 0x6c, 0x62, 0x78, 0xc0, 0x05};
-// rmailbx.example.com. emailbx.example.com.
-const uint8_t compressed_wiredata_minfo2[] = {
- 0x07, 0x72, 0x6d, 0x61, 0x69, 0x6c, 0x62, 0x78, 0x07, 0x65, 0x78,
- 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x07,
- 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x62, 0x78, 0xc0, 0x08};
-
-const generic::MINFO rdata_minfo(minfo_txt);
-const generic::MINFO rdata_minfo2(minfo_txt2);
+const char* const minfo_txt = "rmailbox.example.com. emailbox.example.com.";
+const char* const too_long_label = "01234567890123456789012345678901234567"
+ "89012345678901234567890123";
+
+const generic::MINFO rdata_minfo((string(minfo_txt)));
TEST_F(Rdata_MINFO_Test, createFromText) {
- EXPECT_EQ(Name("root.example.com."), rdata_minfo.getRmailbox());
- EXPECT_EQ(Name("emailbx.example.com."), rdata_minfo.getEmailbox());
+ EXPECT_EQ(Name("rmailbox.example.com."), rdata_minfo.getRmailbox());
+ EXPECT_EQ(Name("emailbox.example.com."), rdata_minfo.getEmailbox());
}
TEST_F(Rdata_MINFO_Test, badText) {
// incomplete text
EXPECT_THROW(generic::MINFO("root.example.com."),
InvalidRdataText);
- // bad name
+ // number of fields (must be 2) is incorrect
+ EXPECT_THROW(generic::MINFO("root.example.com emailbox.example.com. "
+ "example.com."),
+ InvalidRdataText);
+ // bad rmailbox name
EXPECT_THROW(generic::MINFO("root.example.com. emailbx.example.com." +
- too_long_label),
+ string(too_long_label)),
+ TooLongLabel);
+ // bad emailbox name
+ EXPECT_THROW(generic::MINFO("root.example.com." +
+ string(too_long_label) + " emailbx.example.com."),
TooLongLabel);
}
TEST_F(Rdata_MINFO_Test, createFromWire) {
// compressed emailbx name
EXPECT_EQ(0, rdata_minfo.compare(
- *rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
+ *rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
"rdata_minfo_fromWire")));
// compressed rmailbx and emailbx name
EXPECT_EQ(0, rdata_minfo.compare(
- *rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
- "rdata_minfo_fromWire", 30)));
+ *rdataFactoryFromFile(RRType("MINFO"), RRClass::IN(),
+ "rdata_minfo_fromWire", 35)));
// RDLENGTH is too short
- EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
- "rdata_minfo_fromWire", 36),
+ EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
+ "rdata_minfo_fromWire", 41),
InvalidRdataLength);
// RDLENGTH is too long
- EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
- "rdata_minfo_fromWire", 42),
+ EXPECT_THROW(rdataFactoryFromFile(RRType::MINFO(), RRClass::IN(),
+ "rdata_minfo_fromWire", 47),
InvalidRdataLength);
// incomplete name. the error should be detected in the name constructor
- EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass("IN"),
- "rdata_cname_fromWire", 48),
+ EXPECT_THROW(rdataFactoryFromFile(RRType("MINFO"), RRClass::IN(),
+ "rdata_minfo_fromWire", 53),
DNSMessageFORMERR);
}
TEST_F(Rdata_MINFO_Test, toWireBuffer) {
+ obuffer.skip(2);
rdata_minfo.toWire(obuffer);
+ vector<unsigned char> data;
+ UnitTestUtil::readWireData("rdata_minfo_toWireUncompressed.wire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
- obuffer.getData(), obuffer.getLength(),
- uncompressed_wiredata_minfo,
- sizeof(uncompressed_wiredata_minfo));
- obuffer.clear();
- rdata_minfo2.toWire(obuffer);
- EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
- obuffer.getData(), obuffer.getLength(),
- uncompressed_wiredata_minfo2,
- sizeof(uncompressed_wiredata_minfo2));
+ static_cast<const uint8_t *>(obuffer.getData()) + 2,
+ obuffer.getLength() - 2, &data[2], data.size() - 2);
}
TEST_F(Rdata_MINFO_Test, toWireRenderer) {
+ obuffer.skip(2);
rdata_minfo.toWire(renderer);
+ vector<unsigned char> data;
+ UnitTestUtil::readWireData("rdata_minfo_toWire", data);
EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
- obuffer.getData(), obuffer.getLength(),
- compressed_wiredata_minfo,
- sizeof(compressed_wiredata_minfo));
- renderer.clear();
- rdata_minfo2.toWire(renderer);
- EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
- obuffer.getData(), obuffer.getLength(),
- compressed_wiredata_minfo2,
- sizeof(compressed_wiredata_minfo2));
+ static_cast<const uint8_t *>(obuffer.getData()) + 2,
+ obuffer.getLength() - 2, &data[2], data.size() - 2);
}
TEST_F(Rdata_MINFO_Test, toText) {
EXPECT_EQ(minfo_txt, rdata_minfo.toText());
- EXPECT_EQ(minfo_txt2, rdata_minfo2.toText());
}
TEST_F(Rdata_MINFO_Test, compare) {
@@ -145,18 +118,18 @@ TEST_F(Rdata_MINFO_Test, compare) {
EXPECT_EQ(0, rdata_minfo.compare(rdata_minfo));
// names must be compared in case-insensitive manner
- EXPECT_EQ(0, rdata_minfo.compare(generic::MINFO("ROOT.example.com. "
- "emailbx.EXAMPLE.com.")));
+ EXPECT_EQ(0, rdata_minfo.compare(generic::MINFO("RMAILBOX.example.com. "
+ "emailbox.EXAMPLE.com.")));
// another MINFO whose rmailbox name is larger than that of rdata_minfo.
- const generic::MINFO large1_minfo("zzzz.example.com. "
+ const generic::MINFO large1_minfo("zzzzzzzz.example.com. "
"emailbox.example.com.");
EXPECT_GT(0, rdata_minfo.compare(large1_minfo));
EXPECT_LT(0, large1_minfo.compare(rdata_minfo));
// another MINFO whose emailbox name is larger than that of rdata_minfo.
- const generic::MINFO large2_minfo("root.example.com. "
- "zzzzzzz.example.com.");
+ const generic::MINFO large2_minfo("rmailbox.example.com. "
+ "zzzzzzzzzzz.example.com.");
EXPECT_GT(0, rdata_minfo.compare(large2_minfo));
EXPECT_LT(0, large2_minfo.compare(rdata_minfo));
diff --git a/src/lib/dns/tests/testdata/Makefile.am b/src/lib/dns/tests/testdata/Makefile.am
index 344231a..7e90b2c 100644
--- a/src/lib/dns/tests/testdata/Makefile.am
+++ b/src/lib/dns/tests/testdata/Makefile.am
@@ -49,8 +49,7 @@ BUILT_SOURCES += tsig_verify10.wire
# NOTE: keep this in sync with real file listing
# so is included in tarball
-EXTRA_DIST = gen-wiredata.py.in
-EXTRA_DIST += edns_toWire1.spec edns_toWire2.spec
+EXTRA_DIST = edns_toWire1.spec edns_toWire2.spec
EXTRA_DIST += edns_toWire3.spec edns_toWire4.spec
EXTRA_DIST += masterload.txt
EXTRA_DIST += message_fromWire1 message_fromWire2
@@ -102,7 +101,8 @@ 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_srv_fromWire
-EXTRA_DIST += rdata_minfo_fromWire
+EXTRA_DIST += rdata_minfo_fromWire rdata_minfo_toWireUncompressed.spec
+EXTRA_DIST += rdata_minfo_toWireUncompressed.wire rdata_minfo_toWire
EXTRA_DIST += rdata_txt_fromWire1 rdata_txt_fromWire2.spec
EXTRA_DIST += rdata_txt_fromWire3.spec rdata_txt_fromWire4.spec
EXTRA_DIST += rdata_txt_fromWire5.spec rdata_unknown_fromWire
@@ -124,4 +124,4 @@ EXTRA_DIST += tsig_verify7.spec tsig_verify8.spec tsig_verify9.spec
EXTRA_DIST += tsig_verify10.spec
.spec.wire:
- ./gen-wiredata.py -o $@ $<
+ $(PYTHON) $(top_builddir)/src/lib/util/python/gen_wiredata.py -o $@ $<
diff --git a/src/lib/dns/tests/testdata/gen-wiredata.py.in b/src/lib/dns/tests/testdata/gen-wiredata.py.in
deleted file mode 100755
index 818c6e9..0000000
--- a/src/lib/dns/tests/testdata/gen-wiredata.py.in
+++ /dev/null
@@ -1,610 +0,0 @@
-#!@PYTHON@
-
-# Copyright (C) 2010 Internet Systems Consortium.
-#
-# Permission to use, copy, modify, and 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 INTERNET SYSTEMS CONSORTIUM
-# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
-# INTERNET SYSTEMS CONSORTIUM 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.
-
-import configparser, re, time, socket, sys
-from datetime import datetime
-from optparse import OptionParser
-
-re_hex = re.compile(r'^0x[0-9a-fA-F]+')
-re_decimal = re.compile(r'^\d+$')
-re_string = re.compile(r"\'(.*)\'$")
-
-dnssec_timefmt = '%Y%m%d%H%M%S'
-
-dict_qr = { 'query' : 0, 'response' : 1 }
-dict_opcode = { 'query' : 0, 'iquery' : 1, 'status' : 2, 'notify' : 4,
- 'update' : 5 }
-rdict_opcode = dict([(dict_opcode[k], k.upper()) for k in dict_opcode.keys()])
-dict_rcode = { 'noerror' : 0, 'formerr' : 1, 'servfail' : 2, 'nxdomain' : 3,
- 'notimp' : 4, 'refused' : 5, 'yxdomain' : 6, 'yxrrset' : 7,
- 'nxrrset' : 8, 'notauth' : 9, 'notzone' : 10 }
-rdict_rcode = dict([(dict_rcode[k], k.upper()) for k in dict_rcode.keys()])
-dict_rrtype = { 'none' : 0, 'a' : 1, 'ns' : 2, 'md' : 3, 'mf' : 4, 'cname' : 5,
- 'soa' : 6, 'mb' : 7, 'mg' : 8, 'mr' : 9, 'null' : 10,
- 'wks' : 11, 'ptr' : 12, 'hinfo' : 13, 'minfo' : 14, 'mx' : 15,
- 'txt' : 16, 'rp' : 17, 'afsdb' : 18, 'x25' : 19, 'isdn' : 20,
- 'rt' : 21, 'nsap' : 22, 'nsap_tr' : 23, 'sig' : 24, 'key' : 25,
- 'px' : 26, 'gpos' : 27, 'aaaa' : 28, 'loc' : 29, 'nxt' : 30,
- 'srv' : 33, 'naptr' : 35, 'kx' : 36, 'cert' : 37, 'a6' : 38,
- 'dname' : 39, 'opt' : 41, 'apl' : 42, 'ds' : 43, 'sshfp' : 44,
- 'ipseckey' : 45, 'rrsig' : 46, 'nsec' : 47, 'dnskey' : 48,
- 'dhcid' : 49, 'nsec3' : 50, 'nsec3param' : 51, 'hip' : 55,
- 'spf' : 99, 'unspec' : 103, 'tkey' : 249, 'tsig' : 250,
- 'dlv' : 32769, 'ixfr' : 251, 'axfr' : 252, 'mailb' : 253,
- 'maila' : 254, 'any' : 255 }
-rdict_rrtype = dict([(dict_rrtype[k], k.upper()) for k in dict_rrtype.keys()])
-dict_rrclass = { 'in' : 1, 'ch' : 3, 'hs' : 4, 'any' : 255 }
-rdict_rrclass = dict([(dict_rrclass[k], k.upper()) for k in \
- dict_rrclass.keys()])
-dict_algorithm = { 'rsamd5' : 1, 'dh' : 2, 'dsa' : 3, 'ecc' : 4,
- 'rsasha1' : 5 }
-dict_nsec3_algorithm = { 'reserved' : 0, 'sha1' : 1 }
-rdict_algorithm = dict([(dict_algorithm[k], k.upper()) for k in \
- dict_algorithm.keys()])
-rdict_nsec3_algorithm = dict([(dict_nsec3_algorithm[k], k.upper()) for k in \
- dict_nsec3_algorithm.keys()])
-
-header_xtables = { 'qr' : dict_qr, 'opcode' : dict_opcode,
- 'rcode' : dict_rcode }
-question_xtables = { 'rrtype' : dict_rrtype, 'rrclass' : dict_rrclass }
-rrsig_xtables = { 'algorithm' : dict_algorithm }
-
-def parse_value(value, xtable = {}):
- if re.search(re_hex, value):
- return int(value, 16)
- if re.search(re_decimal, value):
- return int(value)
- m = re.match(re_string, value)
- if m:
- return m.group(1)
- lovalue = value.lower()
- if lovalue in xtable:
- return xtable[lovalue]
- return value
-
-def code_totext(code, dict):
- if code in dict.keys():
- return dict[code] + '(' + str(code) + ')'
- return str(code)
-
-def encode_name(name, absolute=True):
- # make sure the name is dot-terminated. duplicate dots will be ignored
- # below.
- name += '.'
- labels = name.split('.')
- wire = ''
- 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:]))
- break
- if absolute or len(l) > 0:
- wire += '%02x' % len(l)
- wire += ''.join(['%02x' % ord(ch) for ch in l])
- if len(l) == 0:
- break
- return wire
-
-def encode_string(name, len=None):
- if type(name) is int and len is not None:
- return '%0.*x' % (len * 2, name)
- return ''.join(['%02x' % ord(ch) for ch in name])
-
-def count_namelabels(name):
- if name == '.': # special case
- return 0
- m = re.match('^(.*)\.$', name)
- if m:
- name = m.group(1)
- return len(name.split('.'))
-
-def get_config(config, section, configobj, xtables = {}):
- try:
- for field in config.options(section):
- value = config.get(section, field)
- if field in xtables.keys():
- xtable = xtables[field]
- else:
- xtable = {}
- configobj.__dict__[field] = parse_value(value, xtable)
- except configparser.NoSectionError:
- return False
- return True
-
-def print_header(f, input_file):
- f.write('''###
-### This data file was auto-generated from ''' + input_file + '''
-###
-''')
-
-class Name:
- name = 'example.com'
- pointer = None # no compression by default
- def dump(self, f):
- name = self.name
- if self.pointer is not None:
- if len(name) > 0 and name[-1] != '.':
- name += '.'
- name += 'ptr=%d' % self.pointer
- name_wire = encode_name(name)
- f.write('\n# DNS Name: %s' % self.name)
- if self.pointer is not None:
- f.write(' + compression pointer: %d' % self.pointer)
- f.write('\n')
- f.write('%s' % name_wire)
- f.write('\n')
-
-class DNSHeader:
- id = 0x1035
- (qr, aa, tc, rd, ra, ad, cd) = 0, 0, 0, 0, 0, 0, 0
- mbz = 0
- rcode = 0 # noerror
- opcode = 0 # query
- (qdcount, ancount, nscount, arcount) = 1, 0, 0, 0
- def dump(self, f):
- f.write('\n# Header Section\n')
- f.write('# ID=' + str(self.id))
- f.write(' QR=' + ('Response' if self.qr else 'Query'))
- f.write(' Opcode=' + code_totext(self.opcode, rdict_opcode))
- f.write(' Rcode=' + code_totext(self.rcode, rdict_rcode))
- f.write('%s' % (' AA' if self.aa else ''))
- f.write('%s' % (' TC' if self.tc else ''))
- f.write('%s' % (' RD' if self.rd else ''))
- f.write('%s' % (' AD' if self.ad else ''))
- f.write('%s' % (' CD' if self.cd else ''))
- f.write('\n')
- f.write('%04x ' % self.id)
- flag_and_code = 0
- flag_and_code |= (self.qr << 15 | self.opcode << 14 | self.aa << 10 |
- self.tc << 9 | self.rd << 8 | self.ra << 7 |
- self.mbz << 6 | self.ad << 5 | self.cd << 4 |
- self.rcode)
- f.write('%04x\n' % flag_and_code)
- f.write('# QDCNT=%d, ANCNT=%d, NSCNT=%d, ARCNT=%d\n' %
- (self.qdcount, self.ancount, self.nscount, self.arcount))
- f.write('%04x %04x %04x %04x\n' % (self.qdcount, self.ancount,
- self.nscount, self.arcount))
-
-class DNSQuestion:
- name = 'example.com.'
- rrtype = parse_value('A', dict_rrtype)
- rrclass = parse_value('IN', dict_rrclass)
- def dump(self, f):
- f.write('\n# Question Section\n')
- f.write('# QNAME=%s QTYPE=%s QCLASS=%s\n' %
- (self.name,
- code_totext(self.rrtype, rdict_rrtype),
- code_totext(self.rrclass, rdict_rrclass)))
- f.write(encode_name(self.name))
- f.write(' %04x %04x\n' % (self.rrtype, self.rrclass))
-
-class EDNS:
- name = '.'
- udpsize = 4096
- extrcode = 0
- version = 0
- do = 0
- mbz = 0
- rdlen = 0
- def dump(self, f):
- f.write('\n# EDNS OPT RR\n')
- f.write('# NAME=%s TYPE=%s UDPSize=%d ExtRcode=%s Version=%s DO=%d\n' %
- (self.name, code_totext(dict_rrtype['opt'], rdict_rrtype),
- self.udpsize, self.extrcode, self.version,
- 1 if self.do else 0))
-
- code_vers = (self.extrcode << 8) | (self.version & 0x00ff)
- extflags = (self.do << 15) | (self.mbz & 0x8000)
- f.write('%s %04x %04x %04x %04x\n' %
- (encode_name(self.name), dict_rrtype['opt'], self.udpsize,
- code_vers, extflags))
- f.write('# RDLEN=%d\n' % self.rdlen)
- f.write('%04x\n' % self.rdlen)
-
-class RR:
- '''This is a base class for various types of RR test data.
- For each RR type (A, AAAA, NS, etc), we define a derived class of RR
- to dump type specific RDATA parameters. This class defines parameters
- common to all types of RDATA, namely the owner name, RR class and TTL.
- The dump() method of derived classes are expected to call dump_header(),
- whose default implementation is provided in this class. This method
- decides whether to dump the test data as an RR (with name, type, class)
- or only as RDATA (with its length), and dumps the corresponding data
- via the specified file object.
-
- By convention we assume derived classes are named after the common
- standard mnemonic of the corresponding RR types. For example, the
- derived class for the RR type SOA should be named "SOA".
-
- Configurable parameters are as follows:
- - as_rr (bool): Whether or not the data is to be dumped as an RR. False
- by default.
- - rr_class (string): The RR class of the data. Only meaningful when the
- data is dumped as an RR. Default is 'IN'.
- - rr_ttl (integer): The TTL value of the RR. Only meaningful when the
- data is dumped as an RR. Default is 86400 (1 day).
- '''
-
- def __init__(self):
- self.as_rr = False
- # only when as_rr is True, same for class/TTL:
- self.rr_name = 'example.com'
- self.rr_class = 'IN'
- self.rr_ttl = 86400
- def dump_header(self, f, rdlen):
- type_txt = self.__class__.__name__
- type_code = parse_value(type_txt, dict_rrtype)
- if self.as_rr:
- rrclass = parse_value(self.rr_class, dict_rrclass)
- f.write('\n# %s RR (QNAME=%s Class=%s TTL=%d RDLEN=%d)\n' %
- (type_txt, self.rr_name,
- code_totext(rrclass, rdict_rrclass), self.rr_ttl, rdlen))
- f.write('%s %04x %04x %08x %04x\n' %
- (encode_name(self.rr_name), type_code, rrclass,
- self.rr_ttl, rdlen))
- else:
- f.write('\n# %s RDATA (RDLEN=%d)\n' % (type_txt, rdlen))
- f.write('%04x\n' % rdlen)
-
-class A(RR):
- rdlen = 4 # fixed by default
- address = '192.0.2.1'
-
- def dump(self, f):
- self.dump_header(f, self.rdlen)
- f.write('# Address=%s\n' % (self.address))
- bin_address = socket.inet_aton(self.address)
- f.write('%02x%02x%02x%02x\n' % (bin_address[0], bin_address[1],
- bin_address[2], bin_address[3]))
-
-class NS(RR):
- rdlen = None # auto calculate
- nsname = 'ns.example.com'
-
- def dump(self, f):
- nsname_wire = encode_name(self.nsname)
- if self.rdlen is None:
- self.rdlen = len(nsname_wire) / 2
- self.dump_header(f, self.rdlen)
- f.write('# NS name=%s\n' % (self.nsname))
- f.write('%s\n' % nsname_wire)
-
-class SOA(RR):
- rdlen = None # auto-calculate
- mname = 'ns.example.com'
- rname = 'root.example.com'
- serial = 2010012601
- refresh = 3600
- retry = 300
- expire = 3600000
- minimum = 1200
- def dump(self, f):
- mname_wire = encode_name(self.mname)
- rname_wire = encode_name(self.rname)
- if self.rdlen is None:
- self.rdlen = int(20 + len(mname_wire) / 2 + len(str(rname_wire)) / 2)
- self.dump_header(f, self.rdlen)
- f.write('# NNAME=%s RNAME=%s\n' % (self.mname, self.rname))
- f.write('%s %s\n' % (mname_wire, rname_wire))
- f.write('# SERIAL(%d) REFRESH(%d) RETRY(%d) EXPIRE(%d) MINIMUM(%d)\n' %
- (self.serial, self.refresh, self.retry, self.expire,
- self.minimum))
- f.write('%08x %08x %08x %08x %08x\n' % (self.serial, self.refresh,
- self.retry, self.expire,
- self.minimum))
-
-class TXT(RR):
- rdlen = None # auto-calculate
- nstring = 1 # number of character-strings
- stringlen = -1 # default string length, auto-calculate
- string = 'Test String' # default string
- def dump(self, f):
- stringlen_list = []
- string_list = []
- wirestring_list = []
- for i in range(0, self.nstring):
- key_string = 'string' + str(i)
- if key_string in self.__dict__:
- string_list.append(self.__dict__[key_string])
- else:
- string_list.append(self.string)
- wirestring_list.append(encode_string(string_list[-1]))
- key_stringlen = 'stringlen' + str(i)
- if key_stringlen in self.__dict__:
- stringlen_list.append(self.__dict__[key_stringlen])
- else:
- stringlen_list.append(self.stringlen)
- if stringlen_list[-1] < 0:
- stringlen_list[-1] = int(len(wirestring_list[-1]) / 2)
- if self.rdlen is None:
- self.rdlen = int(len(''.join(wirestring_list)) / 2) + self.nstring
- self.dump_header(f, self.rdlen)
- for i in range(0, self.nstring):
- f.write('# String Len=%d, String=\"%s\"\n' %
- (stringlen_list[i], string_list[i]))
- f.write('%02x%s%s\n' % (stringlen_list[i],
- ' ' 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
- class.'''
- nbitmap = 1 # number of bitmaps
- block = 0
- maplen = None # default bitmap length, auto-calculate
- bitmap = '040000000003' # an arbtrarily chosen bitmap sample
- def dump(self, f):
- # first, construct the bitmpa data
- block_list = []
- maplen_list = []
- bitmap_list = []
- for i in range(0, self.nbitmap):
- key_bitmap = 'bitmap' + str(i)
- if key_bitmap in self.__dict__:
- bitmap_list.append(self.__dict__[key_bitmap])
- else:
- bitmap_list.append(self.bitmap)
- key_maplen = 'maplen' + str(i)
- if key_maplen in self.__dict__:
- maplen_list.append(self.__dict__[key_maplen])
- else:
- maplen_list.append(self.maplen)
- if maplen_list[-1] is None: # calculate it if not specified
- maplen_list[-1] = int(len(bitmap_list[-1]) / 2)
- key_block = 'block' + str(i)
- if key_block in self.__dict__:
- block_list.append(self.__dict__[key_block])
- else:
- block_list.append(self.block)
-
- # dump RR-type specific part (NSEC or NSEC3)
- self.dump_fixedpart(f, 2 * self.nbitmap + \
- int(len(''.join(bitmap_list)) / 2))
-
- # dump the bitmap
- for i in range(0, self.nbitmap):
- f.write('# Bitmap: Block=%d, Length=%d\n' %
- (block_list[i], maplen_list[i]))
- f.write('%02x %02x %s\n' %
- (block_list[i], maplen_list[i], bitmap_list[i]))
-
-class NSEC(NSECBASE):
- rdlen = None # auto-calculate
- nextname = 'next.example.com'
- def dump_fixedpart(self, f, bitmap_totallen):
- name_wire = encode_name(self.nextname)
- if self.rdlen is None:
- # if rdlen needs to be calculated, it must be based on the bitmap
- # length, because the configured maplen can be fake.
- self.rdlen = int(len(name_wire) / 2) + bitmap_totallen
- f.write('\n# NSEC RDATA (RDLEN=%d)\n' % self.rdlen)
- f.write('%04x\n' % self.rdlen);
- f.write('# Next Name=%s (%d bytes)\n' % (self.nextname,
- int(len(name_wire) / 2)))
- f.write('%s\n' % name_wire)
-
-class NSEC3(NSECBASE):
- rdlen = None # auto-calculate
- hashalg = 1 # SHA-1
- optout = False # opt-out flag
- mbz = 0 # other flag fields (none defined yet)
- iterations = 1
- saltlen = 5
- salt = 's' * saltlen
- hashlen = 20
- hash = 'h' * hashlen
- def dump_fixedpart(self, f, bitmap_totallen):
- if self.rdlen is None:
- # if rdlen needs to be calculated, it must be based on the bitmap
- # length, because the configured maplen can be fake.
- self.rdlen = 4 + 1 + len(self.salt) + 1 + len(self.hash) \
- + bitmap_totallen
- f.write('\n# NSEC3 RDATA (RDLEN=%d)\n' % self.rdlen)
- f.write('%04x\n' % self.rdlen)
- optout_val = 1 if self.optout else 0
- f.write('# Hash Alg=%s, Opt-Out=%d, Other Flags=%0x, Iterations=%d\n' %
- (code_totext(self.hashalg, rdict_nsec3_algorithm),
- optout_val, self.mbz, self.iterations))
- f.write('%02x %02x %04x\n' %
- (self.hashalg, (self.mbz << 1) | optout_val, self.iterations))
- f.write("# Salt Len=%d, Salt='%s'\n" % (self.saltlen, self.salt))
- f.write('%02x%s%s\n' % (self.saltlen,
- ' ' if len(self.salt) > 0 else '',
- encode_string(self.salt)))
- f.write("# Hash Len=%d, Hash='%s'\n" % (self.hashlen, self.hash))
- f.write('%02x%s%s\n' % (self.hashlen,
- ' ' if len(self.hash) > 0 else '',
- encode_string(self.hash)))
-
-class RRSIG:
- rdlen = -1 # auto-calculate
- covered = 1 # A
- algorithm = 5 # RSA-SHA1
- labels = -1 # auto-calculate (#labels of signer)
- originalttl = 3600
- expiration = int(time.mktime(datetime.strptime('20100131120000',
- dnssec_timefmt).timetuple()))
- inception = int(time.mktime(datetime.strptime('20100101120000',
- dnssec_timefmt).timetuple()))
- tag = 0x1035
- signer = 'example.com'
- signature = 0x123456789abcdef123456789abcdef
- def dump(self, f):
- name_wire = encode_name(self.signer)
- sig_wire = '%x' % self.signature
- rdlen = self.rdlen
- if rdlen < 0:
- rdlen = int(18 + len(name_wire) / 2 + len(str(sig_wire)) / 2)
- labels = self.labels
- if labels < 0:
- labels = count_namelabels(self.signer)
- f.write('\n# RRSIG RDATA (RDLEN=%d)\n' % rdlen)
- f.write('%04x\n' % rdlen);
- f.write('# Covered=%s Algorithm=%s Labels=%d OrigTTL=%d\n' %
- (code_totext(self.covered, rdict_rrtype),
- code_totext(self.algorithm, rdict_algorithm), labels,
- self.originalttl))
- f.write('%04x %02x %02x %08x\n' % (self.covered, self.algorithm,
- labels, self.originalttl))
- f.write('# Expiration=%s, Inception=%s\n' %
- (str(self.expiration), str(self.inception)))
- f.write('%08x %08x\n' % (self.expiration, self.inception))
- f.write('# Tag=%d Signer=%s and Signature\n' % (self.tag, self.signer))
- f.write('%04x %s %s\n' % (self.tag, name_wire, sig_wire))
-
-class TSIG(RR):
- rdlen = None # auto-calculate
- algorithm = 'hmac-sha256'
- time_signed = 1286978795 # arbitrarily chosen default
- fudge = 300
- mac_size = None # use a common value for the algorithm
- mac = None # use 'x' * mac_size
- original_id = 2845 # arbitrarily chosen default
- error = 0
- other_len = None # 6 if error is BADTIME; otherwise 0
- other_data = None # use time_signed + fudge + 1 for BADTIME
- dict_macsize = { 'hmac-md5' : 16, 'hmac-sha1' : 20, 'hmac-sha256' : 32 }
-
- # TSIG has some special defaults
- def __init__(self):
- super().__init__()
- self.rr_class = 'ANY'
- self.rr_ttl = 0
-
- def dump(self, f):
- if str(self.algorithm) == 'hmac-md5':
- name_wire = encode_name('hmac-md5.sig-alg.reg.int')
- else:
- name_wire = encode_name(self.algorithm)
- mac_size = self.mac_size
- if mac_size is None:
- if self.algorithm in self.dict_macsize.keys():
- mac_size = self.dict_macsize[self.algorithm]
- else:
- raise RuntimeError('TSIG Mac Size cannot be determined')
- mac = encode_string('x' * mac_size) if self.mac is None else \
- encode_string(self.mac, mac_size)
- other_len = self.other_len
- if other_len is None:
- # 18 = BADTIME
- other_len = 6 if self.error == 18 else 0
- other_data = self.other_data
- if other_data is None:
- other_data = '%012x' % (self.time_signed + self.fudge + 1) \
- if self.error == 18 else ''
- else:
- other_data = encode_string(self.other_data, other_len)
- if self.rdlen is None:
- self.rdlen = int(len(name_wire) / 2 + 16 + len(mac) / 2 + \
- len(other_data) / 2)
- self.dump_header(f, self.rdlen)
- f.write('# Algorithm=%s Time-Signed=%d Fudge=%d\n' %
- (self.algorithm, self.time_signed, self.fudge))
- f.write('%s %012x %04x\n' % (name_wire, self.time_signed, self.fudge))
- f.write('# MAC Size=%d MAC=(see hex)\n' % mac_size)
- f.write('%04x%s\n' % (mac_size, ' ' + mac if len(mac) > 0 else ''))
- f.write('# Original-ID=%d Error=%d\n' % (self.original_id, self.error))
- f.write('%04x %04x\n' % (self.original_id, self.error))
- f.write('# Other-Len=%d Other-Data=(see hex)\n' % other_len)
- f.write('%04x%s\n' % (other_len,
- ' ' + other_data if len(other_data) > 0 else ''))
-
-def get_config_param(section):
- config_param = {'name' : (Name, {}),
- 'header' : (DNSHeader, header_xtables),
- 'question' : (DNSQuestion, question_xtables),
- 'edns' : (EDNS, {}), 'a' : (A, {}), 'ns' : (NS, {}),
- 'soa' : (SOA, {}), 'txt' : (TXT, {}),
- 'rp' : (RP, {}), 'rrsig' : (RRSIG, {}),
- 'nsec' : (NSEC, {}), 'nsec3' : (NSEC3, {}),
- 'tsig' : (TSIG, {}) }
- s = section
- m = re.match('^([^:]+)/\d+$', section)
- if m:
- s = m.group(1)
- return config_param[s]
-
-usage = '''usage: %prog [options] input_file'''
-
-if __name__ == "__main__":
- parser = OptionParser(usage=usage)
- parser.add_option('-o', '--output', action='store', dest='output',
- default=None, metavar='FILE',
- help='output file name [default: prefix of input_file]')
- (options, args) = parser.parse_args()
-
- if len(args) == 0:
- parser.error('input file is missing')
- configfile = args[0]
-
- outputfile = options.output
- if not outputfile:
- m = re.match('(.*)\.[^.]+$', configfile)
- if m:
- outputfile = m.group(1)
- else:
- raise ValueError('output file is not specified and input file is not in the form of "output_file.suffix"')
-
- config = configparser.SafeConfigParser()
- config.read(configfile)
-
- output = open(outputfile, 'w')
-
- print_header(output, configfile)
-
- # First try the 'custom' mode; if it fails assume the standard mode.
- try:
- sections = config.get('custom', 'sections').split(':')
- except configparser.NoSectionError:
- sections = ['header', 'question', 'edns']
-
- for s in sections:
- section_param = get_config_param(s)
- (obj, xtables) = (section_param[0](), section_param[1])
- if get_config(config, s, obj, xtables):
- obj.dump(output)
-
- output.close()
diff --git a/src/lib/dns/tests/testdata/rdata_minfo_fromWire b/src/lib/dns/tests/testdata/rdata_minfo_fromWire
index c50f7f6..d620931 100644
--- a/src/lib/dns/tests/testdata/rdata_minfo_fromWire
+++ b/src/lib/dns/tests/testdata/rdata_minfo_fromWire
@@ -1,38 +1,47 @@
#
# various kinds of MINFO RDATA stored in an input buffer
-#
-# RDLENGHT=28 bytes
+#
+# Valid compressed RDATA for "(rmailbox.example.com. emailbox.example.com.)"
+# RDLENGHT=32 bytes
# 0 1
- 00 1c
-# 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2(bytes)
- 04 72 6f 6f 74 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 07 65 6d
-# 3 4 5 6 7 8 9
- 61 69 6c 62 78 c0 07
+ 00 21
+# RMAILBOX: non compressed
+# 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2 3(bytes)
+#(8) r m a i l b o x (7) e x a m p l e (3) c o m .
+ 08 72 6d 61 69 6c 62 6f 78 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00
+# EMAILBOX: compressed
+# 4 5 6 7 8 9 30 1 2 3 4
+#(8) e m a i l b o x ptr=11
+ 08 65 6d 61 69 6c 62 6f 78 c0 0b
#
-# compressed name
+# Both RMAILBOX and EMAILBOX compressed
# RDLENGHT=04 bytes
-#30 1
+# 5 6
00 04
-# 2 3 4 5(bytes)
- c0 02 c0 14
+# 7 8 9 40(bytes)
+#ptr=02 ptr=24
+ c0 02 c0 18
#
-# length too short
+# rdlength too short
# RDLENGHT=03 bytes
-# 6 7
+# 1 2
00 03
-# 8 9 40 1(bytes)
- c0 02 c0 14
+# 3 4 5 6(bytes)
+#ptr=02 ptr=24
+ c0 02 c0 18
#
-# length too long
+# rdlength too long
# RDLENGHT=25 bytes
-# 2 3
+# 7 8
00 19
-# 4 5 6 7(bytes)
- c0 02 c0 14
+# 9 50 1 2(bytes)
+#ptr=02 ptr=24
+ c0 02 c0 18
#
-# incomplete target name
+# incomplete RMAILBOX NAME
# RDLENGHT=19 bytes
-# 8 9
+# 3 4
00 13
-#50 1 2 3 4 5 6 7 8 9 60 1 2 3 4 5 6 7 8 (bytes)
- 04 72 6f 6f 74 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 07
+# 5 6 7 8 9 60 1 2 3 4 5 6 7 8 9 60 1 2 3 (bytes)
+#(8) r m a i l b o x (7) e x a m p l e (3) c
+ 08 72 6d 61 69 6c 62 6f 78 07 65 78 61 6d 70 6c 65 03 63
diff --git a/src/lib/dns/tests/testdata/rdata_minfo_toWire b/src/lib/dns/tests/testdata/rdata_minfo_toWire
new file mode 100644
index 0000000..c0d09d3
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_minfo_toWire
@@ -0,0 +1,15 @@
+#
+# various kinds of MINFO RDATA stored in an input buffer
+#
+# Valid compressed RDATA for "(rmailbox.example.com. emailbox.example.com.)"
+# RDLENGHT=32 bytes
+# 0 1
+ 00 21
+# RMAILBOX: non compressed
+# 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2 3(bytes)
+#(8) r m a i l b o x (7) e x a m p l e (3) c o m .
+ 08 72 6d 61 69 6c 62 6f 78 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00
+# EMAILBOX: compressed
+# 4 5 6 7 8 9 30 1 2 3 4
+#(8) e m a i l b o x ptr=11
+ 08 65 6d 61 69 6c 62 6f 78 c0 0b
diff --git a/src/lib/dns/tests/testdata/rdata_minfo_toWireUncompressed.spec b/src/lib/dns/tests/testdata/rdata_minfo_toWireUncompressed.spec
new file mode 100644
index 0000000..209b301
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_minfo_toWireUncompressed.spec
@@ -0,0 +1,6 @@
+#
+# A simplest form of MINFO: all default parameters
+#
+[custom]
+sections: minfo
+[minfo]
diff --git a/src/lib/dns/tests/testdata/rdata_minfo_toWireUncompressed.wire b/src/lib/dns/tests/testdata/rdata_minfo_toWireUncompressed.wire
new file mode 100644
index 0000000..bd51833
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_minfo_toWireUncompressed.wire
@@ -0,0 +1,8 @@
+###
+### This data file was auto-generated from rdata_minfo_toWireUncompressed.spec
+###
+
+# MINFO RDATA, RDLEN=44
+002c
+# RMAILBOX=rmailbox.example.com EMAILBOX=emailbox.example.com
+08726d61696c626f78076578616d706c6503636f6d00 08656d61696c626f78076578616d706c6503636f6d00
diff --git a/src/lib/python/isc/config/ccsession.py b/src/lib/python/isc/config/ccsession.py
index 8150729..4fa9d58 100644
--- a/src/lib/python/isc/config/ccsession.py
+++ b/src/lib/python/isc/config/ccsession.py
@@ -425,7 +425,7 @@ class UIModuleCCSession(MultiConfigData):
raise ModuleCCSessionError("Bad config version")
self._set_current_config(config)
- def _add_value_to_list(self, identifier, value):
+ def _add_value_to_list(self, identifier, value, module_spec):
cur_list, status = self.get_value(identifier)
if not cur_list:
cur_list = []
@@ -491,7 +491,7 @@ class UIModuleCCSession(MultiConfigData):
if set_value_str is not None:
value_str += set_value_str
value = isc.cc.data.parse_value_str(value_str)
- self._add_value_to_list(identifier, value)
+ self._add_value_to_list(identifier, value, module_spec)
elif 'named_set_item_spec' in module_spec:
item_name = None
item_value = None
diff --git a/src/lib/python/isc/config/tests/ccsession_test.py b/src/lib/python/isc/config/tests/ccsession_test.py
index c820ad9..351c8e6 100644
--- a/src/lib/python/isc/config/tests/ccsession_test.py
+++ b/src/lib/python/isc/config/tests/ccsession_test.py
@@ -745,6 +745,8 @@ class TestUIModuleCCSession(unittest.TestCase):
uccs.remove_value, "Spec2/item5[123]", None)
uccs.remove_value("Spec2/item5[0]", None)
self.assertEqual({'Spec2': {'item5': []}}, uccs._local_changes)
+ uccs.add_value("Spec2/item5", None);
+ self.assertEqual({'Spec2': {'item5': ['']}}, uccs._local_changes)
def test_add_remove_value_named_set(self):
fake_conn = fakeUIConn()
diff --git a/src/lib/python/isc/notify/notify_out_messages.mes b/src/lib/python/isc/notify/notify_out_messages.mes
index f9de744..570f51e 100644
--- a/src/lib/python/isc/notify/notify_out_messages.mes
+++ b/src/lib/python/isc/notify/notify_out_messages.mes
@@ -78,6 +78,6 @@ message, either in the message parser, or while trying to extract data
from the parsed message. The error is printed, and notify_out will
treat the response as a bad message, but this does point to a
programming error, since all exceptions should have been caught
-explicitely. Please file a bug report. Since there was a response,
+explicitly. Please file a bug report. Since there was a response,
no more notifies will be sent to this server for this notification
event.
diff --git a/src/lib/testutils/testdata/Makefile.am b/src/lib/testutils/testdata/Makefile.am
index 93b9eb9..918d5c5 100644
--- a/src/lib/testutils/testdata/Makefile.am
+++ b/src/lib/testutils/testdata/Makefile.am
@@ -32,4 +32,4 @@ EXTRA_DIST += test2.zone.in
EXTRA_DIST += test2-new.zone.in
.spec.wire:
- $(abs_top_builddir)/src/lib/dns/tests/testdata/gen-wiredata.py -o $@ $<
+ $(PYTHON) $(top_builddir)/src/lib/util/python/gen_wiredata.py -o $@ $<
diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am
index 3db9ac4..0b78b29 100644
--- a/src/lib/util/Makefile.am
+++ b/src/lib/util/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = . io unittests tests pyunittests
+SUBDIRS = . io unittests tests pyunittests python
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/util -I$(top_builddir)/src/lib/util
diff --git a/src/lib/util/python/Makefile.am b/src/lib/util/python/Makefile.am
new file mode 100644
index 0000000..81d528c
--- /dev/null
+++ b/src/lib/util/python/Makefile.am
@@ -0,0 +1 @@
+noinst_SCRIPTS = gen_wiredata.py mkpywrapper.py
diff --git a/src/lib/util/python/gen_wiredata.py.in b/src/lib/util/python/gen_wiredata.py.in
new file mode 100755
index 0000000..e35b37b
--- /dev/null
+++ b/src/lib/util/python/gen_wiredata.py.in
@@ -0,0 +1,1211 @@
+#!@PYTHON@
+
+# Copyright (C) 2010 Internet Systems Consortium.
+#
+# Permission to use, copy, modify, and 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 INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM 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.
+
+"""
+Generator of various types of DNS data in the hex format.
+
+This script reads a human readable specification file (called "spec
+file" hereafter) that defines some type of DNS data (an RDATA, an RR,
+or a complete message) and dumps the defined data to a separate file
+as a "wire format" sequence parsable by the
+UnitTestUtil::readWireData() function (currently defined as part of
+libdns++ tests). Many DNS related tests involve wire format test
+data, so it will be convenient if we can define the data in a more
+intuitive way than writing the entire hex sequence by hand.
+
+Here is a simple example. Consider the following spec file:
+
+ [custom]
+ sections: a
+ [a]
+ as_rr: True
+
+When the script reads this file, it detects the file specifies a single
+component (called "section" here) that consists of a single A RDATA,
+which must be dumped as an RR (not only the part of RDATA). It then
+dumps the following content:
+
+ # A RR (QNAME=example.com Class=IN(1) TTL=86400 RDLEN=4)
+ 076578616d706c6503636f6d00 0001 0001 00015180 0004
+ # Address=192.0.2.1
+ c0000201
+
+As can be seen, the script automatically completes all variable
+parameters of RRs: owner name, class, TTL, RDATA length and data. For
+testing purposes many of these will be the same common one (like
+"example.com" or 192.0.2.1), so it would be convenient if we only have
+to specify non default parameters. To change the RDATA (i.e., the
+IPv4 address), we should add the following line at the end of the spec
+file:
+
+ address: 192.0.2.2
+
+Then the last two lines of the output file will be as follows:
+
+ # Address=192.0.2.2
+ c0000202
+
+In some cases we would rather specify malformed data for tests. This
+script has the ability to specify broken parameters for many types of
+data. For example, we can generate data that would look like an A RR
+but the RDLEN is 3 by adding the following line to the spec file:
+
+ rdlen: 3
+
+Then the first two lines of the output file will be as follows:
+
+ # A RR (QNAME=example.com Class=IN(1) TTL=86400 RDLEN=3)
+ 076578616d706c6503636f6d00 0001 0001 00015180 0003
+
+** USAGE **
+
+ gen_wiredata.py [-o output_file] spec_file
+
+If the -o option is missing, and if the spec_file has a suffix (such as
+in the form of "data.spec"), the output file name will be the prefix
+part of it (as in "data"); if -o is missing and the spec_file does not
+have a suffix, the script will fail.
+
+** SPEC FILE SYNTAX **
+
+A spec file accepted in this script should be in the form of a
+configuration file that is parsable by the Python's standard
+configparser module. In short, it consists of sections; each section
+is identified in the form of [section_name] followed by "name: value"
+entries. Lines beginning with # or ; will be treated as comments.
+Refer to the configparser module documentation for further details of
+the general syntax.
+
+This script has two major modes: the custom mode and the DNS query
+mode. The former generates an arbitrary combination of DNS message
+header, question section, RDATAs or RRs. It is mainly intended to
+generate a test data for a single type of RDATA or RR, or for
+complicated complete DNS messages. The DNS query mode is actually a
+special case of the custom mode, which is a shortcut to generate a
+simple DNS query message (with or without EDNS).
+
+* Custom mode syntax *
+
+By default this script assumes the DNS query mode. To specify the
+custom mode, there must be a special "custom" section in the spec
+file, which should contain 'sections' entry. This value of this
+entryis colon-separated string fields, each of which is either
+"header", "question", "edns", "name", or a string specifying an RR
+type. For RR types the string is lower-cased string mnemonic that
+identifies the type: 'a' for type A, 'ns' for type NS, and so on
+(note: in the current implementation it's case sensitive, and must be
+lower cased).
+
+Each of these fields is interpreted as a section name of the spec
+(configuration), and in that section parameters specific to the
+semantics of the field can be configured.
+
+A "header" section specifies the content of a DNS message header.
+See the documentation of the DNSHeader class of this module for
+configurable parameters.
+
+A "question" section specifies the content of a single question that
+is normally to be placed in the Question section of a DNS message.
+See the documentation of the DNSQuestion class of this module for
+configurable parameters.
+
+An "edns" section specifies the content of an EDNS OPT RR. See the
+documentation of the EDNS class of this module for configurable
+parameters.
+
+A "name" section specifies a domain name with or without compression.
+This is specifically intended to be used for testing name related
+functionalities and would rarely be used with other sections. See the
+documentation of the Name class of this module for configurable
+parameters.
+
+In a specific section for an RR or RDATA, possible entries depend on
+the type. But there are some common configurable entries. See the
+description of the RR class. The most important one would be "as_rr".
+It controls whether the entry should be treated as an RR (with name,
+type, class and TTL) or only as an RDATA. By default as_rr is
+"False", so if an entry is to be intepreted as an RR, an as_rr entry
+must be explicitly specified with a value of "True".
+
+Another common entry is "rdlen". It specifies the RDLEN field value
+of the RR (note: this is included when the entry is interpreted as
+RDATA, too). By default this value is automatically determined by the
+RR type and (it has a variable length) from other fields of RDATA, but
+as shown in the above example, it can be explicitly set, possibly to a
+bogus value for testing against invalid data.
+
+For type specific entries (and their defaults when provided), see the
+documentation of the corresponding Python class defined in this
+module. In general, there should be a class named the same mnemonic
+of the corresponding RR type for each supported type, and they are a
+subclass of the RR class. For example, the "NS" class is defined for
+RR type NS.
+
+Look again at the A RR example shown at the beginning of this
+description. There's a "custom" section, which consists of a
+"sections" entry whose value is a single "a", which means the data to
+be generated is an A RR or RDATA. There's a corresponding "a"
+section, which only specifies that it should be interpreted as an RR
+(all field values of the RR are derived from the default).
+
+If you want to generate a data sequence for two ore more RRs or
+RDATAs, you can specify them in the form of colon-separated fields for
+the "sections" entry. For example, to generate a sequence of A and NS
+RRs in that order, the "custom" section would be something like this:
+
+ [custom]
+ sections: a:ns
+
+and there must be an "ns" section in addtion to "a".
+
+If a sequence of two or more RRs/RDATAs of the same RR type should be
+generated, these should be uniquely indexed with the "/" separator.
+For example, to generate two A RRs, the "custom" section would be as
+follows:
+
+ [custom]
+ sections: a/1:a/2
+
+and there must be "a/1" and "a/2" sections.
+
+Another practical example that would be used for many tests is to
+generate data for a complete DNS ressponse message. The spec file of
+such an example configuration would look like as follows:
+
+ [custom]
+ sections: header:question:a
+ [header]
+ qr: 1
+ ancount: 1
+ [question]
+ [a]
+ as_rr: True
+
+With this configuration, this script will generate test data for a DNS
+response to a query for example.com/IN/A containing one corresponding
+A RR in the answer section.
+
+* DNS query mode syntax *
+
+If the spec file does not contain a "custom" section (that has a
+"sections" entry), this script assumes the DNS query mode. This mode
+is actually a special case of custom mode; it implicitly assumes the
+"sections" entry whose value is "header:question:edns".
+
+In this mode it is expected that the spec file also contains at least
+a "header" and "question" sections, and optionally an "edns" section.
+But the script does not warn or fail even if the expected sections are
+missing.
+
+* Entry value types *
+
+As described above, a section of the spec file accepts entries
+specific to the semantics of the section. They generally correspond
+to DNS message or RR fields.
+
+Many of them are expected to be integral values, for which either decimal or
+hexadecimal representation is accepted, for example:
+
+ rr_ttl: 3600
+ tag: 0x1234
+
+Some others are expected to be string. A string value does not have
+to be quated:
+
+ address: 192.0.2.2
+
+but can also be quoated with single quotes:
+
+ address: '192.0.2.2'
+
+Note 1: a string that can be interpreted as an integer must be quated.
+For example, if you want to set a "string" entry to "3600", it should
+be:
+
+ string: '3600'
+
+instead of
+
+ string: 3600
+
+Note 2: a string enclosed with double quotes is not accepted:
+
+ # This doesn't work:
+ address: "192.0.2.2"
+
+In general, string values are converted to hexadecimal sequences
+according to the semantics of the entry. For instance, a textual IPv4
+address in the above example will be converted to a hexadecimal
+sequence corresponding to a 4-byte integer. So, in many cases, the
+acceptable syntax for a particular string entry value should be
+obvious from the context. There are still some exceptional cases
+especially for complicated RR field values, for which the
+corresponding class documentation should be referenced.
+
+One special string syntax that would be worth noting is domain names,
+which would natually be used in many kinds of entries. The simplest
+form of acceptable syntax is a textual representation of domain names
+such as "example.com" (note: names are always assumed to be
+"absolute", so the trailing dot can be omitted). But a domain name in
+the wire format can also contain a compression pointer. This script
+provides a simple support for name compression with a special notation
+of "ptr=nn" where nn is the numeric pointer value (decimal). For example,
+if the NSDNAME field of an NS RDATA is specified as follows:
+
+ nsname: ns.ptr=12
+
+this script will generate the following output:
+
+ # NS name=ns.ptr=12
+ 026e73c00c
+
+** EXTEND THE SCRIPT **
+
+This script is expected to be extended as we add more support for
+various types of RR. It is encouraged to add support for a new type
+of RR to this script as we see the need for testing that type. Here
+is a simple instruction of how to do that.
+
+Assume you are adding support for "FOO" RR. Also assume that the FOO
+RDATA contains a single field named "value".
+
+What you are expected to do is as follows:
+
+- Define a new class named "FOO" inherited from the RR class. Also
+ define a class variable named "value" for the FOO RDATA field (the
+ variable name can be different from the field name, but it's
+ convenient if it can be easily identifiable.) with an appropriate
+ default value (if possible):
+
+ class FOO(RR):
+ value = 10
+
+ The name of the variable will be (automatically) used as the
+ corresponding entry name in the spec file. So, a spec file that
+ sets this field to 20 would look like this:
+
+ [foo]
+ value: 20
+
+- Define the "dump()" method for class FOO. It must call
+ self.dump_header() (which is derived from class RR) at the
+ beginning. It then prints the RDATA field values in an appropriate
+ way. Assuming the value is a 16-bit integer field, a complete
+ dump() method would look like this:
+
+ def dump(self, f):
+ if self.rdlen is None:
+ self.rdlen = 2
+ self.dump_header(f, self.rdlen)
+ f.write('# Value=%d\\n' % (self.value))
+ f.write('%04x\\n' % (self.value))
+
+ The first f.write() call is not mandatory, but is encouraged to
+ be provided so that the generated files will be more human readable.
+ Depending on the complexity of the RDATA fields, the dump()
+ implementation would be more complicated. In particular, if the
+ RDATA length is variable and the RDLEN field value is not specified
+ in the spec file, the dump() method is normally expected to
+ calculate the correct length and pass it to dump_header(). See the
+ implementation of various derived classes of class RR for actual
+ examples.
+"""
+
+import configparser, re, time, socket, sys
+from datetime import datetime
+from optparse import OptionParser
+
+re_hex = re.compile(r'^0x[0-9a-fA-F]+')
+re_decimal = re.compile(r'^\d+$')
+re_string = re.compile(r"\'(.*)\'$")
+
+dnssec_timefmt = '%Y%m%d%H%M%S'
+
+dict_qr = { 'query' : 0, 'response' : 1 }
+dict_opcode = { 'query' : 0, 'iquery' : 1, 'status' : 2, 'notify' : 4,
+ 'update' : 5 }
+rdict_opcode = dict([(dict_opcode[k], k.upper()) for k in dict_opcode.keys()])
+dict_rcode = { 'noerror' : 0, 'formerr' : 1, 'servfail' : 2, 'nxdomain' : 3,
+ 'notimp' : 4, 'refused' : 5, 'yxdomain' : 6, 'yxrrset' : 7,
+ 'nxrrset' : 8, 'notauth' : 9, 'notzone' : 10 }
+rdict_rcode = dict([(dict_rcode[k], k.upper()) for k in dict_rcode.keys()])
+dict_rrtype = { 'none' : 0, 'a' : 1, 'ns' : 2, 'md' : 3, 'mf' : 4, 'cname' : 5,
+ 'soa' : 6, 'mb' : 7, 'mg' : 8, 'mr' : 9, 'null' : 10,
+ 'wks' : 11, 'ptr' : 12, 'hinfo' : 13, 'minfo' : 14, 'mx' : 15,
+ 'txt' : 16, 'rp' : 17, 'afsdb' : 18, 'x25' : 19, 'isdn' : 20,
+ 'rt' : 21, 'nsap' : 22, 'nsap_tr' : 23, 'sig' : 24, 'key' : 25,
+ 'px' : 26, 'gpos' : 27, 'aaaa' : 28, 'loc' : 29, 'nxt' : 30,
+ 'srv' : 33, 'naptr' : 35, 'kx' : 36, 'cert' : 37, 'a6' : 38,
+ 'dname' : 39, 'opt' : 41, 'apl' : 42, 'ds' : 43, 'sshfp' : 44,
+ 'ipseckey' : 45, 'rrsig' : 46, 'nsec' : 47, 'dnskey' : 48,
+ 'dhcid' : 49, 'nsec3' : 50, 'nsec3param' : 51, 'hip' : 55,
+ 'spf' : 99, 'unspec' : 103, 'tkey' : 249, 'tsig' : 250,
+ 'dlv' : 32769, 'ixfr' : 251, 'axfr' : 252, 'mailb' : 253,
+ 'maila' : 254, 'any' : 255 }
+rdict_rrtype = dict([(dict_rrtype[k], k.upper()) for k in dict_rrtype.keys()])
+dict_rrclass = { 'in' : 1, 'ch' : 3, 'hs' : 4, 'any' : 255 }
+rdict_rrclass = dict([(dict_rrclass[k], k.upper()) for k in \
+ dict_rrclass.keys()])
+dict_algorithm = { 'rsamd5' : 1, 'dh' : 2, 'dsa' : 3, 'ecc' : 4,
+ 'rsasha1' : 5 }
+dict_nsec3_algorithm = { 'reserved' : 0, 'sha1' : 1 }
+rdict_algorithm = dict([(dict_algorithm[k], k.upper()) for k in \
+ dict_algorithm.keys()])
+rdict_nsec3_algorithm = dict([(dict_nsec3_algorithm[k], k.upper()) for k in \
+ dict_nsec3_algorithm.keys()])
+
+header_xtables = { 'qr' : dict_qr, 'opcode' : dict_opcode,
+ 'rcode' : dict_rcode }
+question_xtables = { 'rrtype' : dict_rrtype, 'rrclass' : dict_rrclass }
+
+def parse_value(value, xtable = {}):
+ if re.search(re_hex, value):
+ return int(value, 16)
+ if re.search(re_decimal, value):
+ return int(value)
+ m = re.match(re_string, value)
+ if m:
+ return m.group(1)
+ lovalue = value.lower()
+ if lovalue in xtable:
+ return xtable[lovalue]
+ return value
+
+def code_totext(code, dict):
+ if code in dict.keys():
+ return dict[code] + '(' + str(code) + ')'
+ return str(code)
+
+def encode_name(name, absolute=True):
+ # make sure the name is dot-terminated. duplicate dots will be ignored
+ # below.
+ name += '.'
+ labels = name.split('.')
+ wire = ''
+ 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:]))
+ break
+ if absolute or len(l) > 0:
+ wire += '%02x' % len(l)
+ wire += ''.join(['%02x' % ord(ch) for ch in l])
+ if len(l) == 0:
+ break
+ return wire
+
+def encode_string(name, len=None):
+ if type(name) is int and len is not None:
+ return '%0.*x' % (len * 2, name)
+ return ''.join(['%02x' % ord(ch) for ch in name])
+
+def count_namelabels(name):
+ if name == '.': # special case
+ return 0
+ m = re.match('^(.*)\.$', name)
+ if m:
+ name = m.group(1)
+ return len(name.split('.'))
+
+def get_config(config, section, configobj, xtables = {}):
+ try:
+ for field in config.options(section):
+ value = config.get(section, field)
+ if field in xtables.keys():
+ xtable = xtables[field]
+ else:
+ xtable = {}
+ configobj.__dict__[field] = parse_value(value, xtable)
+ except configparser.NoSectionError:
+ return False
+ return True
+
+def print_header(f, input_file):
+ f.write('''###
+### This data file was auto-generated from ''' + input_file + '''
+###
+''')
+
+class Name:
+ '''Implements rendering a single domain name in the test data format.
+
+ Configurable parameter is as follows (see the description of the
+ same name of attribute for the default value):
+ - name (string): A textual representation of the name, such as
+ 'example.com'.
+ - pointer (int): If specified, compression pointer will be
+ prepended to the generated data with the offset being the value
+ of this parameter.
+ '''
+
+ name = 'example.com'
+ pointer = None # no compression by default
+ def dump(self, f):
+ name = self.name
+ if self.pointer is not None:
+ if len(name) > 0 and name[-1] != '.':
+ name += '.'
+ name += 'ptr=%d' % self.pointer
+ name_wire = encode_name(name)
+ f.write('\n# DNS Name: %s' % self.name)
+ if self.pointer is not None:
+ f.write(' + compression pointer: %d' % self.pointer)
+ f.write('\n')
+ f.write('%s' % name_wire)
+ f.write('\n')
+
+class DNSHeader:
+ '''Implements rendering a DNS Header section in the test data format.
+
+ Configurable parameter is as follows (see the description of the
+ same name of attribute for the default value):
+ - id (16-bit int):
+ - qr, aa, tc, rd, ra, ad, cd (0 or 1): Standard header bits as
+ defined in RFC1035 and RFC4035. If set to 1, the corresponding
+ bit will be set; if set to 0, it will be cleared.
+ - mbz (0-3): The reserved field of the 3rd and 4th octets of the
+ header.
+ - rcode (4-bit int or string): The RCODE field. If specified as a
+ string, it must be the commonly used textual mnemonic of the RCODEs
+ (NOERROR, FORMERR, etc, case insensitive).
+ - opcode (4-bit int or string): The OPCODE field. If specified as
+ a string, it must be the commonly used textual mnemonic of the
+ OPCODEs (QUERY, NOTIFY, etc, case insensitive).
+ - qdcount, ancount, nscount, arcount (16-bit int): The QD/AN/NS/AR
+ COUNT fields, respectively.
+ '''
+
+ id = 0x1035
+ (qr, aa, tc, rd, ra, ad, cd) = 0, 0, 0, 0, 0, 0, 0
+ mbz = 0
+ rcode = 0 # noerror
+ opcode = 0 # query
+ (qdcount, ancount, nscount, arcount) = 1, 0, 0, 0
+
+ def dump(self, f):
+ f.write('\n# Header Section\n')
+ f.write('# ID=' + str(self.id))
+ f.write(' QR=' + ('Response' if self.qr else 'Query'))
+ f.write(' Opcode=' + code_totext(self.opcode, rdict_opcode))
+ f.write(' Rcode=' + code_totext(self.rcode, rdict_rcode))
+ f.write('%s' % (' AA' if self.aa else ''))
+ f.write('%s' % (' TC' if self.tc else ''))
+ f.write('%s' % (' RD' if self.rd else ''))
+ f.write('%s' % (' AD' if self.ad else ''))
+ f.write('%s' % (' CD' if self.cd else ''))
+ f.write('\n')
+ f.write('%04x ' % self.id)
+ flag_and_code = 0
+ flag_and_code |= (self.qr << 15 | self.opcode << 14 | self.aa << 10 |
+ self.tc << 9 | self.rd << 8 | self.ra << 7 |
+ self.mbz << 6 | self.ad << 5 | self.cd << 4 |
+ self.rcode)
+ f.write('%04x\n' % flag_and_code)
+ f.write('# QDCNT=%d, ANCNT=%d, NSCNT=%d, ARCNT=%d\n' %
+ (self.qdcount, self.ancount, self.nscount, self.arcount))
+ f.write('%04x %04x %04x %04x\n' % (self.qdcount, self.ancount,
+ self.nscount, self.arcount))
+
+class DNSQuestion:
+ '''Implements rendering a DNS question in the test data format.
+
+ Configurable parameter is as follows (see the description of the
+ same name of attribute for the default value):
+ - name (string): The QNAME. The string must be interpreted as a
+ valid domain name.
+ - rrtype (int or string): The question type. If specified
+ as an integer, it must be the 16-bit RR type value of the
+ covered type. If specifed as a string, it must be the textual
+ mnemonic of the type.
+ - rrclass (int or string): The question class. If specified as an
+ integer, it must be the 16-bit RR class value of the covered
+ type. If specifed as a string, it must be the textual mnemonic
+ of the class.
+ '''
+ name = 'example.com.'
+ rrtype = parse_value('A', dict_rrtype)
+ rrclass = parse_value('IN', dict_rrclass)
+
+ def dump(self, f):
+ f.write('\n# Question Section\n')
+ f.write('# QNAME=%s QTYPE=%s QCLASS=%s\n' %
+ (self.name,
+ code_totext(self.rrtype, rdict_rrtype),
+ code_totext(self.rrclass, rdict_rrclass)))
+ f.write(encode_name(self.name))
+ f.write(' %04x %04x\n' % (self.rrtype, self.rrclass))
+
+class EDNS:
+ '''Implements rendering EDNS OPT RR in the test data format.
+
+ Configurable parameter is as follows (see the description of the
+ same name of attribute for the default value):
+ - name (string): The owner name of the OPT RR. The string must be
+ interpreted as a valid domain name.
+ - udpsize (16-bit int): The UDP payload size (set as the RR class)
+ - extrcode (8-bit int): The upper 8 bits of the extended RCODE.
+ - version (8-bit int): The EDNS version.
+ - do (int): The DNSSEC DO bit. The bit will be set if this value
+ is 1; otherwise the bit will be unset.
+ - mbz (15-bit int): The rest of the flags field.
+ - rdlen (16-bit int): The RDLEN field. Note: right now specifying
+ a non 0 value (except for making bogus data) doesn't make sense
+ because there is no way to configure RDATA.
+ '''
+ name = '.'
+ udpsize = 4096
+ extrcode = 0
+ version = 0
+ do = 0
+ mbz = 0
+ rdlen = 0
+ def dump(self, f):
+ f.write('\n# EDNS OPT RR\n')
+ f.write('# NAME=%s TYPE=%s UDPSize=%d ExtRcode=%s Version=%s DO=%d\n' %
+ (self.name, code_totext(dict_rrtype['opt'], rdict_rrtype),
+ self.udpsize, self.extrcode, self.version,
+ 1 if self.do else 0))
+
+ code_vers = (self.extrcode << 8) | (self.version & 0x00ff)
+ extflags = (self.do << 15) | (self.mbz & ~0x8000)
+ f.write('%s %04x %04x %04x %04x\n' %
+ (encode_name(self.name), dict_rrtype['opt'], self.udpsize,
+ code_vers, extflags))
+ f.write('# RDLEN=%d\n' % self.rdlen)
+ f.write('%04x\n' % self.rdlen)
+
+class RR:
+ '''This is a base class for various types of RR test data.
+ For each RR type (A, AAAA, NS, etc), we define a derived class of RR
+ to dump type specific RDATA parameters. This class defines parameters
+ common to all types of RDATA, namely the owner name, RR class and TTL.
+ The dump() method of derived classes are expected to call dump_header(),
+ whose default implementation is provided in this class. This method
+ decides whether to dump the test data as an RR (with name, type, class)
+ or only as RDATA (with its length), and dumps the corresponding data
+ via the specified file object.
+
+ By convention we assume derived classes are named after the common
+ standard mnemonic of the corresponding RR types. For example, the
+ derived class for the RR type SOA should be named "SOA".
+
+ Configurable parameters are as follows:
+ - as_rr (bool): Whether or not the data is to be dumped as an RR.
+ False by default.
+ - rr_name (string): The owner name of the RR. The string must be
+ interpreted as a valid domain name (compression pointer can be
+ contained). Default is 'example.com.'
+ - rr_class (string): The RR class of the data. Only meaningful
+ when the data is dumped as an RR. Default is 'IN'.
+ - rr_ttl (int): The TTL value of the RR. Only meaningful when
+ the data is dumped as an RR. Default is 86400 (1 day).
+ - rdlen (int): 16-bit RDATA length. It can be None (i.e. omitted
+ in the spec file), in which case the actual length of the
+ generated RDATA is automatically determined and used; if
+ negative, the RDLEN field will be omitted from the output data.
+ (Note that omitting RDLEN with as_rr being True is mostly
+ meaningless, although the script doesn't complain about it).
+ Default is None.
+ '''
+
+ def __init__(self):
+ self.as_rr = False
+ # only when as_rr is True, same for class/TTL:
+ self.rr_name = 'example.com'
+ self.rr_class = 'IN'
+ self.rr_ttl = 86400
+ self.rdlen = None
+
+ def dump_header(self, f, rdlen):
+ type_txt = self.__class__.__name__
+ type_code = parse_value(type_txt, dict_rrtype)
+ rdlen_spec = ''
+ rdlen_data = ''
+ if rdlen >= 0:
+ rdlen_spec = ', RDLEN=%d' % rdlen
+ rdlen_data = '%04x' % rdlen
+ if self.as_rr:
+ rrclass = parse_value(self.rr_class, dict_rrclass)
+ f.write('\n# %s RR (QNAME=%s Class=%s TTL=%d%s)\n' %
+ (type_txt, self.rr_name,
+ code_totext(rrclass, rdict_rrclass), self.rr_ttl,
+ rdlen_spec))
+ f.write('%s %04x %04x %08x %s\n' %
+ (encode_name(self.rr_name), type_code, rrclass,
+ self.rr_ttl, rdlen_data))
+ else:
+ f.write('\n# %s RDATA%s\n' % (type_txt, rdlen_spec))
+ f.write('%s\n' % rdlen_data)
+
+class A(RR):
+ '''Implements rendering A RDATA (of class IN) in the test data format.
+
+ Configurable parameter is as follows (see the description of the
+ same name of attribute for the default value):
+ - address (string): The address field. This must be a valid textual
+ IPv4 address.
+ '''
+ RDLEN_DEFAULT = 4 # fixed by default
+ address = '192.0.2.1'
+
+ def dump(self, f):
+ if self.rdlen is None:
+ self.rdlen = self.RDLEN_DEFAULT
+ self.dump_header(f, self.rdlen)
+ f.write('# Address=%s\n' % (self.address))
+ bin_address = socket.inet_aton(self.address)
+ f.write('%02x%02x%02x%02x\n' % (bin_address[0], bin_address[1],
+ bin_address[2], bin_address[3]))
+
+class AAAA(RR):
+ '''Implements rendering AAAA RDATA (of class IN) in the test data
+ format.
+
+ Configurable parameter is as follows (see the description of the
+ same name of attribute for the default value):
+ - address (string): The address field. This must be a valid textual
+ IPv6 address.
+ '''
+ RDLEN_DEFAULT = 16 # fixed by default
+ address = '2001:db8::1'
+
+ def dump(self, f):
+ if self.rdlen is None:
+ self.rdlen = self.RDLEN_DEFAULT
+ self.dump_header(f, self.rdlen)
+ f.write('# Address=%s\n' % (self.address))
+ bin_address = socket.inet_pton(socket.AF_INET6, self.address)
+ [f.write('%02x' % x) for x in bin_address]
+ f.write('\n')
+
+class NS(RR):
+ '''Implements rendering NS RDATA in the test data format.
+
+ Configurable parameter is as follows (see the description of the
+ same name of attribute for the default value):
+ - nsname (string): The NSDNAME field. The string must be
+ interpreted as a valid domain name.
+ '''
+
+ nsname = 'ns.example.com'
+
+ def dump(self, f):
+ nsname_wire = encode_name(self.nsname)
+ if self.rdlen is None:
+ self.rdlen = len(nsname_wire) / 2
+ self.dump_header(f, self.rdlen)
+ f.write('# NS name=%s\n' % (self.nsname))
+ f.write('%s\n' % nsname_wire)
+
+class SOA(RR):
+ '''Implements rendering SOA RDATA in the test data format.
+
+ Configurable parameters are as follows (see the description of the
+ same name of attribute for the default value):
+ - mname/rname (string): The MNAME/RNAME fields, respectively. The
+ string must be interpreted as a valid domain name.
+ - serial (32-bit int): The SERIAL field
+ - refresh (32-bit int): The REFRESH field
+ - retry (32-bit int): The RETRY field
+ - expire (32-bit int): The EXPIRE field
+ - minimum (32-bit int): The MINIMUM field
+ '''
+
+ mname = 'ns.example.com'
+ rname = 'root.example.com'
+ serial = 2010012601
+ refresh = 3600
+ retry = 300
+ expire = 3600000
+ minimum = 1200
+ def dump(self, f):
+ mname_wire = encode_name(self.mname)
+ rname_wire = encode_name(self.rname)
+ if self.rdlen is None:
+ self.rdlen = int(20 + len(mname_wire) / 2 + len(str(rname_wire)) / 2)
+ self.dump_header(f, self.rdlen)
+ f.write('# NNAME=%s RNAME=%s\n' % (self.mname, self.rname))
+ f.write('%s %s\n' % (mname_wire, rname_wire))
+ f.write('# SERIAL(%d) REFRESH(%d) RETRY(%d) EXPIRE(%d) MINIMUM(%d)\n' %
+ (self.serial, self.refresh, self.retry, self.expire,
+ self.minimum))
+ f.write('%08x %08x %08x %08x %08x\n' % (self.serial, self.refresh,
+ self.retry, self.expire,
+ self.minimum))
+
+class TXT(RR):
+ '''Implements rendering TXT RDATA in the test data format.
+
+ Configurable parameters are as follows (see the description of the
+ same name of attribute for the default value):
+ - nstring (int): number of character-strings
+ - stringlenN (int) (int, N = 0, ..., nstring-1): the length of the
+ N-th character-string.
+ - stringN (string, N = 0, ..., nstring-1): the N-th
+ character-string.
+ - stringlen (int): the default string. If nstring >= 1 and the
+ corresponding stringlenN isn't specified in the spec file, this
+ value will be used. If this parameter isn't specified either,
+ the length of the string will be used. Note that it means
+ this parameter (or any stringlenN) doesn't have to be specified
+ unless you want to intentially build a broken character string.
+ - string (string): the default string. If nstring >= 1 and the
+ corresponding stringN isn't specified in the spec file, this
+ string will be used.
+ '''
+
+ nstring = 1
+ stringlen = None
+ string = 'Test String'
+
+ def dump(self, f):
+ stringlen_list = []
+ string_list = []
+ wirestring_list = []
+ for i in range(0, self.nstring):
+ key_string = 'string' + str(i)
+ if key_string in self.__dict__:
+ string_list.append(self.__dict__[key_string])
+ else:
+ string_list.append(self.string)
+ wirestring_list.append(encode_string(string_list[-1]))
+ key_stringlen = 'stringlen' + str(i)
+ if key_stringlen in self.__dict__:
+ stringlen_list.append(self.__dict__[key_stringlen])
+ else:
+ stringlen_list.append(self.stringlen)
+ if stringlen_list[-1] is None:
+ stringlen_list[-1] = int(len(wirestring_list[-1]) / 2)
+ if self.rdlen is None:
+ self.rdlen = int(len(''.join(wirestring_list)) / 2) + self.nstring
+ self.dump_header(f, self.rdlen)
+ for i in range(0, self.nstring):
+ f.write('# String Len=%d, String=\"%s\"\n' %
+ (stringlen_list[i], string_list[i]))
+ f.write('%02x%s%s\n' % (stringlen_list[i],
+ ' ' if len(wirestring_list[i]) > 0 else '',
+ wirestring_list[i]))
+
+class RP(RR):
+ '''Implements rendering RP RDATA in the test data format.
+
+ Configurable parameters are as follows (see the description of the
+ same name of attribute for the default value):
+ - mailbox (string): The mailbox field.
+ - text (string): The text field.
+ These strings must be interpreted as a valid domain name.
+ '''
+ 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)
+ self.dump_header(f, self.rdlen)
+ f.write('# MAILBOX=%s TEXT=%s\n' % (self.mailbox, self.text))
+ f.write('%s %s\n' % (mailbox_wire, text_wire))
+
+class MINFO(RR):
+ '''Implements rendering MINFO RDATA in the test data format.
+
+ Configurable parameters are as follows (see the description of the
+ same name of attribute for the default value):
+ - rmailbox (string): The rmailbox field.
+ - emailbox (string): The emailbox field.
+ These strings must be interpreted as a valid domain name.
+ '''
+ rmailbox = 'rmailbox.example.com'
+ emailbox = 'emailbox.example.com'
+ def dump(self, f):
+ rmailbox_wire = encode_name(self.rmailbox)
+ emailbox_wire = encode_name(self.emailbox)
+ if self.rdlen is None:
+ self.rdlen = (len(rmailbox_wire) + len(emailbox_wire)) / 2
+ else:
+ self.rdlen = int(self.rdlen)
+ self.dump_header(f, self.rdlen)
+ f.write('# RMAILBOX=%s EMAILBOX=%s\n' % (self.rmailbox, self.emailbox))
+ f.write('%s %s\n' % (rmailbox_wire, emailbox_wire))
+
+class NSECBASE(RR):
+ '''Implements rendering NSEC/NSEC3 type bitmaps commonly used for
+ these RRs. The NSEC and NSEC3 classes will be inherited from this
+ class.
+
+ Configurable parameters are as follows (see the description of the
+ same name of attribute for the default value):
+ - nbitmap (int): The number of type bitmaps.
+ The following three define the bitmaps. If suffixed with "N"
+ (0 <= N < nbitmaps), it means the definition for the N-th bitmap.
+ If there is no suffix (e.g., just "block", it means the default
+ for any unspecified values)
+ - block[N] (8-bit int): The Window Block.
+ - maplen[N] (8-bit int): The Bitmap Length. The default "maplen"
+ can also be unspecified (with being set to None), in which case
+ the corresponding length will be calculated from the bitmap.
+ - bitmap[N] (string): The Bitmap. This must be the hexadecimal
+ representation of the bitmap field. For example, for a bitmap
+ where the 7th and 15th bits (and only these bits) are set, it
+ must be '0101'. Note also that the value must be quated with
+ single quatations because it could also be interpreted as an
+ integer.
+ '''
+ nbitmap = 1 # number of bitmaps
+ block = 0
+ maplen = None # default bitmap length, auto-calculate
+ bitmap = '040000000003' # an arbtrarily chosen bitmap sample
+ def dump(self, f):
+ # first, construct the bitmpa data
+ block_list = []
+ maplen_list = []
+ bitmap_list = []
+ for i in range(0, self.nbitmap):
+ key_bitmap = 'bitmap' + str(i)
+ if key_bitmap in self.__dict__:
+ bitmap_list.append(self.__dict__[key_bitmap])
+ else:
+ bitmap_list.append(self.bitmap)
+ key_maplen = 'maplen' + str(i)
+ if key_maplen in self.__dict__:
+ maplen_list.append(self.__dict__[key_maplen])
+ else:
+ maplen_list.append(self.maplen)
+ if maplen_list[-1] is None: # calculate it if not specified
+ maplen_list[-1] = int(len(bitmap_list[-1]) / 2)
+ key_block = 'block' + str(i)
+ if key_block in self.__dict__:
+ block_list.append(self.__dict__[key_block])
+ else:
+ block_list.append(self.block)
+
+ # dump RR-type specific part (NSEC or NSEC3)
+ self.dump_fixedpart(f, 2 * self.nbitmap + \
+ int(len(''.join(bitmap_list)) / 2))
+
+ # dump the bitmap
+ for i in range(0, self.nbitmap):
+ f.write('# Bitmap: Block=%d, Length=%d\n' %
+ (block_list[i], maplen_list[i]))
+ f.write('%02x %02x %s\n' %
+ (block_list[i], maplen_list[i], bitmap_list[i]))
+
+class NSEC(NSECBASE):
+ '''Implements rendering NSEC RDATA in the test data format.
+
+ Configurable parameters are as follows (see the description of the
+ same name of attribute for the default value):
+ - Type bitmap related parameters: see class NSECBASE
+ - nextname (string): The Next Domain Name field. The string must be
+ interpreted as a valid domain name.
+ '''
+
+ nextname = 'next.example.com'
+ def dump_fixedpart(self, f, bitmap_totallen):
+ name_wire = encode_name(self.nextname)
+ if self.rdlen is None:
+ # if rdlen needs to be calculated, it must be based on the bitmap
+ # length, because the configured maplen can be fake.
+ self.rdlen = int(len(name_wire) / 2) + bitmap_totallen
+ self.dump_header(f, self.rdlen)
+ f.write('# Next Name=%s (%d bytes)\n' % (self.nextname,
+ int(len(name_wire) / 2)))
+ f.write('%s\n' % name_wire)
+
+class NSEC3(NSECBASE):
+ '''Implements rendering NSEC3 RDATA in the test data format.
+
+ Configurable parameters are as follows (see the description of the
+ same name of attribute for the default value):
+ - Type bitmap related parameters: see class NSECBASE
+ - hashalg (8-bit int): The Hash Algorithm field. Note that
+ currently the only defined algorithm is SHA-1, for which a value
+ of 1 will be used, and it's the default. So this implementation
+ does not support any string representation right now.
+ - optout (bool): The Opt-Out flag of the Flags field.
+ - mbz (7-bit int): The rest of the Flags field. This value will
+ be left shifted for 1 bit and then OR-ed with optout to
+ construct the complete Flags field.
+ - iterations (16-bit int): The Iterations field.
+ - saltlen (int): The Salt Length field.
+ - salt (string): The Salt field. It is converted to a sequence of
+ ascii codes and its hexadecimal representation will be used.
+ - hashlen (int): The Hash Length field.
+ - hash (string): The Next Hashed Owner Name field. This parameter
+ is interpreted as "salt".
+ '''
+
+ hashalg = 1 # SHA-1
+ optout = False # opt-out flag
+ mbz = 0 # other flag fields (none defined yet)
+ iterations = 1
+ saltlen = 5
+ salt = 's' * saltlen
+ hashlen = 20
+ hash = 'h' * hashlen
+ def dump_fixedpart(self, f, bitmap_totallen):
+ if self.rdlen is None:
+ # if rdlen needs to be calculated, it must be based on the bitmap
+ # length, because the configured maplen can be fake.
+ self.rdlen = 4 + 1 + len(self.salt) + 1 + len(self.hash) \
+ + bitmap_totallen
+ self.dump_header(f, self.rdlen)
+ optout_val = 1 if self.optout else 0
+ f.write('# Hash Alg=%s, Opt-Out=%d, Other Flags=%0x, Iterations=%d\n' %
+ (code_totext(self.hashalg, rdict_nsec3_algorithm),
+ optout_val, self.mbz, self.iterations))
+ f.write('%02x %02x %04x\n' %
+ (self.hashalg, (self.mbz << 1) | optout_val, self.iterations))
+ f.write("# Salt Len=%d, Salt='%s'\n" % (self.saltlen, self.salt))
+ f.write('%02x%s%s\n' % (self.saltlen,
+ ' ' if len(self.salt) > 0 else '',
+ encode_string(self.salt)))
+ f.write("# Hash Len=%d, Hash='%s'\n" % (self.hashlen, self.hash))
+ f.write('%02x%s%s\n' % (self.hashlen,
+ ' ' if len(self.hash) > 0 else '',
+ encode_string(self.hash)))
+
+class RRSIG(RR):
+ '''Implements rendering RRSIG RDATA in the test data format.
+
+ Configurable parameters are as follows (see the description of the
+ same name of attribute for the default value):
+ - covered (int or string): The Type Covered field. If specified
+ as an integer, it must be the 16-bit RR type value of the
+ covered type. If specifed as a string, it must be the textual
+ mnemonic of the type.
+ - algorithm (int or string): The Algorithm field. If specified
+ as an integer, it must be the 8-bit algorithm number as defined
+ in RFC4034. If specifed as a string, it must be one of the keys
+ of dict_algorithm (case insensitive).
+ - labels (int): The Labels field. If omitted (the corresponding
+ variable being set to None), the number of labels of "signer"
+ (excluding the trailing null label as specified in RFC4034) will
+ be used.
+ - originalttl (32-bit int): The Original TTL field.
+ - expiration (32-bit int): The Expiration TTL field.
+ - inception (32-bit int): The Inception TTL field.
+ - tag (16-bit int): The Key Tag field.
+ - signer (string): The Signer's Name field. The string must be
+ interpreted as a valid domain name.
+ - signature (int): The Signature field. Right now only a simple
+ integer form is supported. A prefix of "0" will be prepended if
+ the resulting hexadecimal representation consists of an odd
+ number of characters.
+ '''
+
+ covered = 'A'
+ algorithm = 'RSASHA1'
+ labels = None # auto-calculate (#labels of signer)
+ originalttl = 3600
+ expiration = int(time.mktime(datetime.strptime('20100131120000',
+ dnssec_timefmt).timetuple()))
+ inception = int(time.mktime(datetime.strptime('20100101120000',
+ dnssec_timefmt).timetuple()))
+ tag = 0x1035
+ signer = 'example.com'
+ signature = 0x123456789abcdef123456789abcdef
+
+ def dump(self, f):
+ name_wire = encode_name(self.signer)
+ sig_wire = '%x' % self.signature
+ if len(sig_wire) % 2 != 0:
+ sig_wire = '0' + sig_wire
+ if self.rdlen is None:
+ self.rdlen = int(18 + len(name_wire) / 2 + len(str(sig_wire)) / 2)
+ self.dump_header(f, self.rdlen)
+
+ if type(self.covered) is str:
+ self.covered = dict_rrtype[self.covered.lower()]
+ if type(self.algorithm) is str:
+ self.algorithm = dict_algorithm[self.algorithm.lower()]
+ if self.labels is None:
+ self.labels = count_namelabels(self.signer)
+ f.write('# Covered=%s Algorithm=%s Labels=%d OrigTTL=%d\n' %
+ (code_totext(self.covered, rdict_rrtype),
+ code_totext(self.algorithm, rdict_algorithm), self.labels,
+ self.originalttl))
+ f.write('%04x %02x %02x %08x\n' % (self.covered, self.algorithm,
+ self.labels, self.originalttl))
+ f.write('# Expiration=%s, Inception=%s\n' %
+ (str(self.expiration), str(self.inception)))
+ f.write('%08x %08x\n' % (self.expiration, self.inception))
+ f.write('# Tag=%d Signer=%s and Signature\n' % (self.tag, self.signer))
+ f.write('%04x %s %s\n' % (self.tag, name_wire, sig_wire))
+
+class TSIG(RR):
+ '''Implements rendering TSIG RDATA in the test data format.
+
+ As a meta RR type TSIG uses some non common parameters. This
+ class overrides some of the default attributes of the RR class
+ accordingly:
+ - rr_class is set to 'ANY'
+ - rr_ttl is set to 0
+ Like other derived classes these can be overridden via the spec
+ file.
+
+ Other configurable parameters are as follows (see the description
+ of the same name of attribute for the default value):
+ - algorithm (string): The Algorithm Name field. The value is
+ generally interpreted as a domain name string, and will
+ typically be one of the standard algorithm names defined in
+ RFC4635. For convenience, however, a shortcut value "hmac-md5"
+ is allowed instead of the standard "hmac-md5.sig-alg.reg.int".
+ - time_signed (48-bit int): The Time Signed field.
+ - fudge (16-bit int): The Fudge field.
+ - mac_size (int): The MAC Size field. If omitted, the common value
+ determined by the algorithm will be used.
+ - mac (int or string): The MAC field. If specified as an integer,
+ the integer value is used as the MAC, possibly with prepended
+ 0's so that the total length will be mac_size. If specifed as a
+ string, it is converted to a sequence of ascii codes and its
+ hexadecimal representation will be used. So, for example, if
+ "mac" is set to 'abc', it will be converted to '616263'. Note
+ that in this case the length of "mac" may not be equal to
+ mac_size. If unspecified, the mac_size number of '78' (ascii
+ code of 'x') will be used.
+ - original_id (16-bit int): The Original ID field.
+ - error (16-bit int): The Error field.
+ - other_len (int): The Other Len field.
+ - other_data (int or string): The Other Data field. This is
+ interpreted just like "mac" except that other_len is used
+ instead of mac_size. If unspecified this will be empty unless
+ the "error" is set to 18 (which means the "BADTIME" error), in
+ which case a hexadecimal representation of "time_signed + fudge
+ + 1" will be used.
+ '''
+
+ algorithm = 'hmac-sha256'
+ time_signed = 1286978795 # arbitrarily chosen default
+ fudge = 300
+ mac_size = None # use a common value for the algorithm
+ mac = None # use 'x' * mac_size
+ original_id = 2845 # arbitrarily chosen default
+ error = 0
+ other_len = None # 6 if error is BADTIME; otherwise 0
+ other_data = None # use time_signed + fudge + 1 for BADTIME
+ dict_macsize = { 'hmac-md5' : 16, 'hmac-sha1' : 20, 'hmac-sha256' : 32 }
+
+ # TSIG has some special defaults
+ def __init__(self):
+ super().__init__()
+ self.rr_class = 'ANY'
+ self.rr_ttl = 0
+
+ def dump(self, f):
+ if str(self.algorithm) == 'hmac-md5':
+ name_wire = encode_name('hmac-md5.sig-alg.reg.int')
+ else:
+ name_wire = encode_name(self.algorithm)
+ mac_size = self.mac_size
+ if mac_size is None:
+ if self.algorithm in self.dict_macsize.keys():
+ mac_size = self.dict_macsize[self.algorithm]
+ else:
+ raise RuntimeError('TSIG Mac Size cannot be determined')
+ mac = encode_string('x' * mac_size) if self.mac is None else \
+ encode_string(self.mac, mac_size)
+ other_len = self.other_len
+ if other_len is None:
+ # 18 = BADTIME
+ other_len = 6 if self.error == 18 else 0
+ other_data = self.other_data
+ if other_data is None:
+ other_data = '%012x' % (self.time_signed + self.fudge + 1) \
+ if self.error == 18 else ''
+ else:
+ other_data = encode_string(self.other_data, other_len)
+ if self.rdlen is None:
+ self.rdlen = int(len(name_wire) / 2 + 16 + len(mac) / 2 + \
+ len(other_data) / 2)
+ self.dump_header(f, self.rdlen)
+ f.write('# Algorithm=%s Time-Signed=%d Fudge=%d\n' %
+ (self.algorithm, self.time_signed, self.fudge))
+ f.write('%s %012x %04x\n' % (name_wire, self.time_signed, self.fudge))
+ f.write('# MAC Size=%d MAC=(see hex)\n' % mac_size)
+ f.write('%04x%s\n' % (mac_size, ' ' + mac if len(mac) > 0 else ''))
+ f.write('# Original-ID=%d Error=%d\n' % (self.original_id, self.error))
+ f.write('%04x %04x\n' % (self.original_id, self.error))
+ f.write('# Other-Len=%d Other-Data=(see hex)\n' % other_len)
+ f.write('%04x%s\n' % (other_len,
+ ' ' + other_data if len(other_data) > 0 else ''))
+
+# Build section-class mapping
+config_param = { 'name' : (Name, {}),
+ 'header' : (DNSHeader, header_xtables),
+ 'question' : (DNSQuestion, question_xtables),
+ 'edns' : (EDNS, {}) }
+for rrtype in dict_rrtype.keys():
+ # For any supported RR types add the tuple of (RR_CLASS, {}).
+ # We expect KeyError as not all the types are supported, and simply
+ # ignore them.
+ try:
+ cur_mod = sys.modules[__name__]
+ config_param[rrtype] = (cur_mod.__dict__[rrtype.upper()], {})
+ except KeyError:
+ pass
+
+def get_config_param(section):
+ s = section
+ m = re.match('^([^:]+)/\d+$', section)
+ if m:
+ s = m.group(1)
+ return config_param[s]
+
+usage = '''usage: %prog [options] input_file'''
+
+if __name__ == "__main__":
+ parser = OptionParser(usage=usage)
+ parser.add_option('-o', '--output', action='store', dest='output',
+ default=None, metavar='FILE',
+ help='output file name [default: prefix of input_file]')
+ (options, args) = parser.parse_args()
+
+ if len(args) == 0:
+ parser.error('input file is missing')
+ configfile = args[0]
+
+ outputfile = options.output
+ if not outputfile:
+ m = re.match('(.*)\.[^.]+$', configfile)
+ if m:
+ outputfile = m.group(1)
+ else:
+ raise ValueError('output file is not specified and input file is not in the form of "output_file.suffix"')
+
+ config = configparser.SafeConfigParser()
+ config.read(configfile)
+
+ output = open(outputfile, 'w')
+
+ print_header(output, configfile)
+
+ # First try the 'custom' mode; if it fails assume the query mode.
+ try:
+ sections = config.get('custom', 'sections').split(':')
+ except configparser.NoSectionError:
+ sections = ['header', 'question', 'edns']
+
+ for s in sections:
+ section_param = get_config_param(s)
+ (obj, xtables) = (section_param[0](), section_param[1])
+ if get_config(config, s, obj, xtables):
+ obj.dump(output)
+
+ output.close()
More information about the bind10-changes
mailing list