Browse Source

[2656] Add SRV implementation

Mukund Sivaraman 12 years ago
parent
commit
af2672cf15

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

@@ -42,6 +42,7 @@ new_rdata_factory_users = [('aaaa', 'in'),
                            ('ptr', 'generic'),
                            ('soa', 'generic'),
                            ('spf', 'generic'),
+                           ('srv', 'in'),
                            ('txt', 'generic')
                           ]
 

+ 30 - 3
src/lib/dns/rdata/in_1/srv_33.cc

@@ -112,14 +112,41 @@ SRV::SRV(InputBuffer& buffer, size_t rdata_len) {
         isc_throw(InvalidRdataLength, "SRV too short");
     }
 
-    uint16_t priority = buffer.readUint16();
-    uint16_t weight = buffer.readUint16();
-    uint16_t port = buffer.readUint16();
+    const uint16_t priority = buffer.readUint16();
+    const uint16_t weight = buffer.readUint16();
+    const uint16_t port = buffer.readUint16();
     const Name targetname(buffer);
 
     impl_ = new SRVImpl(priority, weight, port, targetname);
 }
 
+SRV::SRV(MasterLexer& lexer, const Name*, MasterLoader::Options,
+         MasterLoaderCallbacks&)
+{
+    uint32_t num = lexer.getNextToken(MasterToken::NUMBER).getNumber();
+    if (num > 65535) {
+        isc_throw(InvalidRdataText, "Invalid SRV priority");
+    }
+    const uint16_t priority = static_cast<uint16_t>(num);
+
+    num = lexer.getNextToken(MasterToken::NUMBER).getNumber();
+    if (num > 65535) {
+        isc_throw(InvalidRdataText, "Invalid SRV weight");
+    }
+    const uint16_t weight = static_cast<uint16_t>(num);
+
+    num = lexer.getNextToken(MasterToken::NUMBER).getNumber();
+    if (num > 65535) {
+        isc_throw(InvalidRdataText, "Invalid SRV port");
+    }
+    const uint16_t port = static_cast<uint16_t>(num);
+
+    const Name targetname =
+        Name(lexer.getNextToken(MasterToken::QSTRING).getString());
+
+    impl_ = new SRVImpl(priority, weight, port, targetname);
+}
+
 /// \brief The copy constructor.
 ///
 /// It internally allocates a resource, and if it fails a corresponding

+ 10 - 0
src/lib/dns/tests/rdata_srv_unittest.cc

@@ -125,6 +125,16 @@ TEST_F(Rdata_SRV_Test, createFromLexer) {
                                      "1 5 1500 a.example.com.")));
 
     // Exceptions cause NULL to be returned.
+
+    // Bad priority
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::SRV(), RRClass::IN(),
+                                             "65536 5 1500 "
+                                             "a.example.com."));
+    // Bad weight
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::SRV(), RRClass::IN(),
+                                             "1 65536 1500 "
+                                             "a.example.com."));
+    // Bad port
     EXPECT_FALSE(test::createRdataUsingLexer(RRType::SRV(), RRClass::IN(),
                                              "1 5 281474976710656 "
                                              "a.example.com."));