Parcourir la source

[1866] auto-generate RRType defs for all (yet fully) unsupported types.

added some tests to check the definitions are complete and correct.
JINMEI Tatuya il y a 12 ans
Parent
commit
463700b34d
40 fichiers modifiés avec 268 ajouts et 2 suppressions
  1. 36 0
      src/lib/dns/Makefile.am
  2. 10 2
      src/lib/dns/gen-rdatacode.py.in
  3. 4 0
      src/lib/dns/rdata/generic/caa_257.txt
  4. 4 0
      src/lib/dns/rdata/generic/cert_37.txt
  5. 4 0
      src/lib/dns/rdata/generic/gpos_27.txt
  6. 4 0
      src/lib/dns/rdata/generic/hip_55.txt
  7. 4 0
      src/lib/dns/rdata/generic/ipseckey_45.txt
  8. 4 0
      src/lib/dns/rdata/generic/isdn_20.txt
  9. 4 0
      src/lib/dns/rdata/generic/key_25.txt
  10. 4 0
      src/lib/dns/rdata/generic/l32_105.txt
  11. 4 0
      src/lib/dns/rdata/generic/l64_106.txt
  12. 4 0
      src/lib/dns/rdata/generic/loc_29.txt
  13. 4 0
      src/lib/dns/rdata/generic/lp_107.txt
  14. 4 0
      src/lib/dns/rdata/generic/maila_254.txt
  15. 4 0
      src/lib/dns/rdata/generic/mailb_253.txt
  16. 4 0
      src/lib/dns/rdata/generic/mb_7.txt
  17. 4 0
      src/lib/dns/rdata/generic/md_3.txt
  18. 4 0
      src/lib/dns/rdata/generic/mf_4.txt
  19. 4 0
      src/lib/dns/rdata/generic/mg_8.txt
  20. 4 0
      src/lib/dns/rdata/generic/mr_9.txt
  21. 4 0
      src/lib/dns/rdata/generic/nid_104.txt
  22. 4 0
      src/lib/dns/rdata/generic/null_10.txt
  23. 4 0
      src/lib/dns/rdata/generic/nxt_30.txt
  24. 4 0
      src/lib/dns/rdata/generic/proforma.txt
  25. 4 0
      src/lib/dns/rdata/generic/rt_21.txt
  26. 4 0
      src/lib/dns/rdata/generic/sig_24.txt
  27. 4 0
      src/lib/dns/rdata/generic/tkey_249.txt
  28. 4 0
      src/lib/dns/rdata/generic/tlsa_52.txt
  29. 4 0
      src/lib/dns/rdata/generic/unspec_103.txt
  30. 4 0
      src/lib/dns/rdata/generic/uri_256.txt
  31. 4 0
      src/lib/dns/rdata/generic/x25_19.txt
  32. 4 0
      src/lib/dns/rdata/in_1/a6_38.txt
  33. 4 0
      src/lib/dns/rdata/in_1/apl_42.txt
  34. 4 0
      src/lib/dns/rdata/in_1/kx_36.txt
  35. 4 0
      src/lib/dns/rdata/in_1/nsap-ptr_23.txt
  36. 4 0
      src/lib/dns/rdata/in_1/nsap_22.txt
  37. 4 0
      src/lib/dns/rdata/in_1/px_26.txt
  38. 4 0
      src/lib/dns/rdata/in_1/wks_11.txt
  39. 25 0
      src/lib/dns/tests/rrclass_unittest.cc
  40. 53 0
      src/lib/dns/tests/rrtype_unittest.cc

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

@@ -79,6 +79,35 @@ 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/generic/cert_37.txt
+EXTRA_DIST += rdata/generic/gpos_27.txt
+EXTRA_DIST += rdata/generic/hip_55.txt
+EXTRA_DIST += rdata/generic/ipseckey_45.txt
+EXTRA_DIST += rdata/generic/isdn_20.txt
+EXTRA_DIST += rdata/generic/key_25.txt
+EXTRA_DIST += rdata/generic/l32_105.txt
+EXTRA_DIST += rdata/generic/l64_106.txt
+EXTRA_DIST += rdata/generic/loc_29.txt
+EXTRA_DIST += rdata/generic/lp_107.txt
+EXTRA_DIST += rdata/generic/mb_7.txt
+EXTRA_DIST += rdata/generic/md_3.txt
+EXTRA_DIST += rdata/generic/mf_4.txt
+EXTRA_DIST += rdata/generic/mg_8.txt
+EXTRA_DIST += rdata/generic/mr_9.txt
+EXTRA_DIST += rdata/generic/nid_104.txt
+EXTRA_DIST += rdata/generic/null_10.txt
+EXTRA_DIST += rdata/generic/nxt_30.txt
+EXTRA_DIST += rdata/generic/proforma.txt
+EXTRA_DIST += rdata/generic/rt_21.txt
+EXTRA_DIST += rdata/generic/sig_24.txt
+EXTRA_DIST += rdata/generic/tkey_249.txt
+EXTRA_DIST += rdata/generic/tlsa_52.txt
+EXTRA_DIST += rdata/generic/unspec_103.txt
+EXTRA_DIST += rdata/generic/uri_256.txt
+EXTRA_DIST += rdata/generic/x25_19.txt
+EXTRA_DIST += rdata/generic/maila_254.txt
+EXTRA_DIST += rdata/generic/mailb_253.txt
+EXTRA_DIST += rdata/generic/caa_257.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
@@ -89,6 +118,13 @@ 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/in_1/a6_38.txt
+EXTRA_DIST += rdata/in_1/apl_42.txt
+EXTRA_DIST += rdata/in_1/kx_36.txt
+EXTRA_DIST += rdata/in_1/nsap-ptr_23.txt
+EXTRA_DIST += rdata/in_1/nsap_22.txt
+EXTRA_DIST += rdata/in_1/px_26.txt
+EXTRA_DIST += rdata/in_1/wks_11.txt
 EXTRA_DIST += rdata/none_254
 #EXTRA_DIST += rdata/template.cc
 #EXTRA_DIST += rdata/template.h

+ 10 - 2
src/lib/dns/gen-rdatacode.py.in

@@ -40,7 +40,7 @@ new_rdata_factory_users = [('aaaa', 'in'),
                            ('txt', 'generic')
                           ]
 
-re_typecode = re.compile('([\da-z]+)_(\d+)')
+re_typecode = re.compile('([\da-z\-]+)_(\d+)')
 classcode2txt = {}
 typecode2txt = {}
 # "AXFR"=>252 etc: for meta types and types well-known but not implemented
@@ -286,7 +286,15 @@ def generate_typeclasscode(fileprefix, basemtime, code2txt, type_or_class):
     pydef_txt = ''
     for code in code2txt.keys():
         codetxt = code2txt[code].upper()
-        declarationtxt += ' ' * 4 + 'static const RR' + cap_key + '& ' + codetxt + '();\n'
+        # Workaround by heuristics: there's a "NULL" RR type, but it would
+        # cause conflict with the C/C++ macro.  We use Null as a special case.
+        if codetxt == 'NULL':
+            codetxt = 'Null'
+        # Likewise, convert "NSAP-PTR" to "NSAP_PTR".
+        if codetxt == 'NSAP-PTR':
+            codetxt = "NSAP_PTR"
+        declarationtxt += ' ' * 4 + 'static const RR' + cap_key + '& ' + \
+            codetxt + '();\n'
         deftxt += '''inline const RR''' + cap_key + '''&
 RR''' + cap_key + '''::''' + codetxt + '''() {
     static RR''' + cap_key + ''' ''' + lower_key + '''(''' + code + ''');

+ 4 - 0
src/lib/dns/rdata/generic/caa_257.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/cert_37.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/gpos_27.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/hip_55.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/ipseckey_45.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/isdn_20.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/key_25.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/l32_105.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/l64_106.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/loc_29.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/lp_107.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/maila_254.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/mailb_253.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/mb_7.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/md_3.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/mf_4.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/mg_8.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/mr_9.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/nid_104.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/null_10.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/nxt_30.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/proforma.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/rt_21.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/sig_24.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/tkey_249.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/tlsa_52.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/unspec_103.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/uri_256.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/generic/x25_19.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/in_1/a6_38.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/in_1/apl_42.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/in_1/kx_36.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/in_1/nsap-ptr_23.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/in_1/nsap_22.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/in_1/px_26.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 4 - 0
src/lib/dns/rdata/in_1/wks_11.txt

@@ -0,0 +1,4 @@
+This RR type is not yet implemented; this file is used to generate
+the corresponding RRType constant and a mapping with its textual
+representation, without the Rdata code.  When the Rdata support is
+complete this file must be removed.

+ 25 - 0
src/lib/dns/tests/rrclass_unittest.cc

@@ -148,4 +148,29 @@ TEST_F(RRClassTest, LeftShiftOperator) {
     oss << RRClass::IN();
     EXPECT_EQ(RRClass::IN().toText(), oss.str());
 }
+
+// Below, we'll check definitions for all well-known RR classes; whether they
+// are defined and have the correct parameter values.  Test data are generated
+// from the list available at:
+// http://www.iana.org/assignments/dns-parameters/dns-parameters.xml
+struct ClassParam {
+    const char* const txt;      // "IN", "CH", etc
+    const uint16_t code;        // 1, 3,
+    const RRClass& (*obj)();     // RRClass::IN(), etc
+} known_classes[] = {
+    {"IN", 1, RRClass::IN}, {"CH", 3, RRClass::CH}, {"HS", 4, RRClass::HS},
+    {"NONE", 254, RRClass::NONE}, {"ANY", 255, RRClass::ANY},
+    {NULL, 0, NULL}
+};
+
+TEST(RRClassConstTest, wellKnowns) {
+    for (int i = 0; known_classes[i].txt; ++i) {
+        SCOPED_TRACE("Checking well known RRClass: " +
+                     string(known_classes[i].txt));
+        EXPECT_EQ(known_classes[i].code,
+                  RRClass(known_classes[i].txt).getCode());
+        EXPECT_EQ(known_classes[i].code,
+                  (*known_classes[i].obj)().getCode());
+    }
+}
 }

+ 53 - 0
src/lib/dns/tests/rrtype_unittest.cc

@@ -145,4 +145,57 @@ TEST_F(RRTypeTest, LeftShiftOperator) {
     oss << RRType::A();
     EXPECT_EQ(RRType::A().toText(), oss.str());
 }
+
+// Below, we'll check definitions for all well-known RR types; whether they
+// are defined and have the correct parameter values.  Test data are generated
+// from the list available at:
+// http://www.iana.org/assignments/dns-parameters/dns-parameters.xml
+struct TypeParam {
+    const char* const txt;      // "A", "AAAA", "NS", etc
+    const uint16_t code;        // 1, 28, 2, etc
+    const RRType& (*obj)();     // RRType::A(), etc
+} known_types[] = {
+    {"A", 1, RRType::A}, {"NS", 2, RRType::NS}, {"MD", 3, RRType::MD},
+    {"MF", 4, RRType::MF}, {"CNAME", 5, RRType::CNAME},
+    {"SOA", 6, RRType::SOA}, {"MB", 7, RRType::MB}, {"MG", 8, RRType::MG},
+    {"MR", 9, RRType::MR}, {"NULL", 10, RRType::Null},
+    {"WKS", 11, RRType::WKS}, {"PTR", 12, RRType::PTR},
+    {"HINFO", 13, RRType::HINFO}, {"MINFO", 14, RRType::MINFO},
+    {"MX", 15, RRType::MX}, {"TXT", 16, RRType::TXT}, {"RP", 17, RRType::RP},
+    {"AFSDB", 18, RRType::AFSDB}, {"X25", 19, RRType::X25},
+    {"ISDN", 20, RRType::ISDN}, {"RT", 21, RRType::RT},
+    {"NSAP", 22, RRType::NSAP}, {"NSAP-PTR", 23, RRType::NSAP_PTR},
+    {"SIG", 24, RRType::SIG}, {"KEY", 25, RRType::KEY},
+    {"PX", 26, RRType::PX}, {"GPOS", 27, RRType::GPOS},
+    {"AAAA", 28, RRType::AAAA}, {"LOC", 29, RRType::LOC},
+    {"NXT", 30, RRType::NXT}, {"SRV", 33, RRType::SRV},
+    {"NAPTR", 35, RRType::NAPTR}, {"KX", 36, RRType::KX},
+    {"CERT", 37, RRType::CERT}, {"A6", 38, RRType::A6},
+    {"DNAME", 39, RRType::DNAME}, {"OPT", 41, RRType::OPT},
+    {"APL", 42, RRType::APL}, {"DS", 43, RRType::DS},
+    {"SSHFP", 44, RRType::SSHFP}, {"IPSECKEY", 45, RRType::IPSECKEY},
+    {"RRSIG", 46, RRType::RRSIG}, {"NSEC", 47, RRType::NSEC},
+    {"DNSKEY", 48, RRType::DNSKEY}, {"DHCID", 49, RRType::DHCID},
+    {"NSEC3", 50, RRType::NSEC3}, {"NSEC3PARAM", 51, RRType::NSEC3PARAM},
+    {"TLSA", 52, RRType::TLSA}, {"HIP", 55, RRType::HIP},
+    {"SPF", 99, RRType::SPF}, {"UNSPEC", 103, RRType::UNSPEC},
+    {"NID", 104, RRType::NID}, {"L32", 105, RRType::L32},
+    {"L64", 106, RRType::L64}, {"LP", 107, RRType::LP},
+    {"TKEY", 249, RRType::TKEY}, {"TSIG", 250, RRType::TSIG},
+    {"IXFR", 251, RRType::IXFR}, {"AXFR", 252, RRType::AXFR},
+    {"MAILB", 253, RRType::MAILB}, {"MAILA", 254, RRType::MAILA},
+    {"ANY", 255, RRType::ANY}, {"URI", 256, RRType::URI},
+    {"CAA", 257, RRType::CAA}, {"DLV", 32769, RRType::DLV},
+    {NULL, 0, NULL}
+};
+
+TEST(RRTypeConstTest, wellKnowns) {
+    for (int i = 0; known_types[i].txt; ++i) {
+        SCOPED_TRACE("Checking well known RRType: " +
+                     string(known_types[i].txt));
+        EXPECT_EQ(known_types[i].code, RRType(known_types[i].txt).getCode());
+        EXPECT_EQ(known_types[i].code,
+                  (*known_types[i].obj)().getCode());
+    }
+}
 }