Browse Source

[1866] added framework to handle meta/non-(fully-)supported RRtypes.

now some parameters for ANY, AXFR, IXFR types and NONE class are
auto-generated, and corresponding hardcoding was removed.
JINMEI Tatuya 12 years ago
parent
commit
0479cb528e

+ 5 - 0
src/lib/dns/Makefile.am

@@ -76,6 +76,9 @@ EXTRA_DIST += rdata/generic/minfo_14.cc
 EXTRA_DIST += rdata/generic/minfo_14.h
 EXTRA_DIST += rdata/generic/afsdb_18.cc
 EXTRA_DIST += rdata/generic/afsdb_18.h
+EXTRA_DIST += rdata/generic/any_255.txt
+EXTRA_DIST += rdata/generic/axfr_252.txt
+EXTRA_DIST += rdata/generic/ixfr_251.txt
 EXTRA_DIST += rdata/hs_4/a_1.cc
 EXTRA_DIST += rdata/hs_4/a_1.h
 EXTRA_DIST += rdata/in_1/a_1.cc
@@ -86,8 +89,10 @@ EXTRA_DIST += rdata/in_1/dhcid_49.cc
 EXTRA_DIST += rdata/in_1/dhcid_49.h
 EXTRA_DIST += rdata/in_1/srv_33.cc
 EXTRA_DIST += rdata/in_1/srv_33.h
+EXTRA_DIST += rdata/none_254
 #EXTRA_DIST += rdata/template.cc
 #EXTRA_DIST += rdata/template.h
+#EXTRA_DIST += rdata/template.txt
 
 noinst_SCRIPTS = gen-rdatacode.py
 

+ 22 - 1
src/lib/dns/gen-rdatacode.py.in

@@ -43,6 +43,10 @@ new_rdata_factory_users = [('aaaa', 'in'),
 re_typecode = re.compile('([\da-z]+)_(\d+)')
 classcode2txt = {}
 typecode2txt = {}
+# "AXFR"=>252 etc: for meta types and types well-known but not implemented
+meta_types = {}
+# "NONE"=>254 etc: for classes that don't have any known types
+meta_classes = {}
 typeandclass = []
 generic_code = 65536            # something larger than any code value
 rdata_declarations = ''
@@ -177,6 +181,9 @@ def import_definitions(classcode2txt, typecode2txt, typeandclass):
             # also apply to files.
             filelist = os.listdir(classdir)
             filelist.sort()
+            if len(filelist) == 0: # if there's no known types treat it as meta
+                meta_classes[class_txt] = class_code
+                continue
             for file in filelist:
                 file = classdir + os.sep + file
                 m = re_typecode.match(os.path.split(file)[1])
@@ -185,7 +192,11 @@ def import_definitions(classcode2txt, typecode2txt, typeandclass):
                     type_code = m.group(2)
                     if not type_code in typecode2txt:
                         typecode2txt[type_code] = type_txt
-                    if re.search('\cc$', file):
+                    if re.search('\.txt$', file): # we use .txt for meta types
+                        if rdatadef_mtime < getmtime(file):
+                            rdatadef_mtime = getmtime(file)
+                        meta_types[type_txt] = type_code
+                    elif re.search('\cc$', file):
                         if rdatadef_mtime < getmtime(file):
                             rdatadef_mtime = getmtime(file)
                         class_definitions += import_classdef(class_txt, file)
@@ -351,6 +362,16 @@ def generate_rrparam(fileprefix, basemtime):
             typeandclassparams += ', RdataFactoryPtr(new ' + rdf_class + '<'
             typeandclassparams += class_txt + '::' + type_utxt + '>()));\n'
 
+    typeandclassparams += indent + '// Meta and non-implemented RR types\n'
+    for type_txt, type_code in meta_types.items():
+        typeandclassparams += indent + \
+            'addType("' + type_txt.upper() + '", ' + str(type_code) + ');\n'
+
+    typeandclassparams += indent + '// Meta classes\n'
+    for cls_txt, cls_code in meta_classes.items():
+        typeandclassparams += indent + \
+            'addClass("' + cls_txt.upper() + '", ' + str(cls_code) + ');\n'
+
     rrparam_temp = open(placeholder, 'r')
     rrparam_out = open(outputfile, 'w')
     rrparam_out.write(heading_txt)

+ 0 - 12
src/lib/dns/python/pydnspp.cc

@@ -527,10 +527,6 @@ initModulePart_RRClass(PyObject* mod) {
 
         // Incorporate auto-generated RRClass constants
 #include <dns/python/rrclass_constants_inc.cc>
-
-        // We still need to define some special classes by hand (for now)
-        installClassVariable(rrclass_type, "NONE",
-                             createRRClassObject(RRClass::NONE()));
     } catch (const std::exception& ex) {
         const std::string ex_what =
             "Unexpected failure in RRClass initialization: " +
@@ -620,14 +616,6 @@ initModulePart_RRType(PyObject* mod) {
 
         // Incorporate auto-generated RRType constants
 #include <dns/python/rrtype_constants_inc.cc>
-
-        // We still need to define some special types by hand (for now)
-        installClassVariable(rrtype_type, "IXFR",
-                                 createRRTypeObject(RRType::IXFR()));
-        installClassVariable(rrtype_type, "AXFR",
-                             createRRTypeObject(RRType::AXFR()));
-        installClassVariable(rrtype_type, "ANY",
-                             createRRTypeObject(RRType::ANY()));
     } catch (const std::exception& ex) {
         const std::string ex_what =
             "Unexpected failure in RRType initialization: " +

+ 1 - 0
src/lib/dns/rdata/generic/any_255.txt

@@ -0,0 +1 @@
+This is a meta type and doesn't have any Rdata definition.

+ 1 - 0
src/lib/dns/rdata/generic/axfr_252.txt

@@ -0,0 +1 @@
+This is a meta type and doesn't have any Rdata definition.

+ 1 - 0
src/lib/dns/rdata/generic/ixfr_251.txt

@@ -0,0 +1 @@
+This is a meta type and doesn't have any Rdata definition.

+ 8 - 0
src/lib/dns/rdata/template.txt

@@ -0,0 +1,8 @@
+For "meta" RR types (i.e., types that don't have Rdata definitions)
+and standard types that have not yet been supported in this
+implementation, place "typename_nn.txt" under the appropriate
+directory (where "typename" is the standard textual mnemonic of the
+type and "nn" is decimal code of the type, e.g. axfr_252.txt).
+Its content doesn't matter.  Then the auto-generate script will
+just generate constant RRTypes and text conversion code for these
+types, skipping Rdata related definitions.

+ 0 - 14
src/lib/dns/rrclass-placeholder.h

@@ -294,28 +294,14 @@ public:
 
     // BEGIN_WELL_KNOWN_CLASS_DECLARATIONS
     // END_WELL_KNOWN_CLASS_DECLARATIONS
-    
-    static const RRClass& NONE();
 
 private:
-    // \brief Meta-classes
-    enum {
-        RRCLASS_RESERVED0 = 0,
-        RRCLASS_NONE = 254
-    };
     uint16_t classcode_;
 };
 
 // BEGIN_WELL_KNOWN_CLASS_DEFINITIONS
 // END_WELL_KNOWN_CLASS_DEFINITIONS
 
-inline const RRClass&
-RRClass::NONE() {
-    static RRClass rrclass(RRCLASS_NONE);
-
-    return (rrclass);
-}
-
 ///
 /// \brief Insert the \c RRClass as a string into stream.
 ///

+ 0 - 30
src/lib/dns/rrtype-placeholder.h

@@ -262,43 +262,13 @@ public:
     // BEGIN_WELL_KNOWN_TYPE_DECLARATIONS
     // END_WELL_KNOWN_TYPE_DECLARATIONS
 
-    static const RRType& IXFR();
-    static const RRType& AXFR();
-    static const RRType& ANY();
-
 private:
-    // \brief Meta-classes
-    // XXX: these should be implemented using rrparamregistry
-    enum {
-        RRTYPE_IXFR = 251,
-        RRTYPE_AXFR = 252,
-        RRTYPE_ANY = 255
-    };
-
     uint16_t typecode_;
 };
 
 // BEGIN_WELL_KNOWN_TYPE_DEFINITIONS
 // END_WELL_KNOWN_TYPE_DEFINITIONS
 
-inline const RRType&
-RRType::IXFR() {
-    static RRType rrtype(RRTYPE_IXFR);
-    return (rrtype);
-}
-
-inline const RRType&
-RRType::AXFR() {
-    static RRType rrtype(RRTYPE_AXFR);
-    return (rrtype);
-}
-
-inline const RRType&
-RRType::ANY() {
-    static RRType rrtype(RRTYPE_ANY);
-    return (rrtype);
-}
-
 ///
 /// \brief Insert the \c RRType as a string into stream.
 ///

+ 1 - 1
src/lib/dns/tests/rrset_unittest.cc

@@ -205,7 +205,7 @@ TEST_F(RRsetTest, toText) {
     // Unless it is type ANY or NONE
     EXPECT_EQ("test.example.com. 3600 ANY A\n",
               rrset_any_a_empty.toText());
-    EXPECT_EQ("test.example.com. 3600 CLASS254 A\n",
+    EXPECT_EQ("test.example.com. 3600 NONE A\n",
               rrset_none_a_empty.toText());
 }
 

+ 4 - 4
src/lib/python/isc/ddns/tests/session_tests.py

@@ -130,8 +130,8 @@ class SessionModuleTests(unittest.TestCase):
                          str(rrset2))
 
         rrset3 = convert_rrset_class(rrset2, RRClass.NONE)
-        self.assertEqual("www.example.org. 3600 CLASS254 A \\# 4 " +
-                         "c0000201\nwww.example.org. 3600 CLASS254 " +
+        self.assertEqual("www.example.org. 3600 NONE A \\# 4 " +
+                         "c0000201\nwww.example.org. 3600 NONE " +
                          "A \\# 4 c0000202\n",
                          str(rrset3))
 
@@ -399,8 +399,8 @@ class SessionTest(SessionTestBase):
                          str(rrset2))
 
         rrset3 = convert_rrset_class(rrset2, RRClass.NONE)
-        self.assertEqual("www.example.org. 3600 CLASS254 A \\# 4 " +
-                         "c0000201\nwww.example.org. 3600 CLASS254 " +
+        self.assertEqual("www.example.org. 3600 NONE A \\# 4 " +
+                         "c0000201\nwww.example.org. 3600 NONE " +
                          "A \\# 4 c0000202\n",
                          str(rrset3))