]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2656] Add SRV implementation
authorMukund Sivaraman <muks@isc.org>
Thu, 24 Jan 2013 13:30:50 +0000 (19:00 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 29 Jan 2013 06:01:10 +0000 (11:31 +0530)
src/lib/dns/gen-rdatacode.py.in
src/lib/dns/rdata/in_1/srv_33.cc
src/lib/dns/tests/rdata_srv_unittest.cc

index 721d9b8f64b0e80d8bb51973e310a7b07c77b1d1..ab2fa2e148eb65e50cc54aac1d878d3ff0ce2cba 100755 (executable)
@@ -42,6 +42,7 @@ new_rdata_factory_users = [('aaaa', 'in'),
                            ('ptr', 'generic'),
                            ('soa', 'generic'),
                            ('spf', 'generic'),
+                           ('srv', 'in'),
                            ('txt', 'generic')
                           ]
 
index af8bbe3ad2a3c408be355324d9e65128949dfa2c..8d900e62f558e50b70154fb12b0c150e909523fc 100644 (file)
@@ -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
index 066755f437fcd50b4336c0cd286110cedfa8d9de..5c7998040b6be030ce2c5e3adcd537c78d4e21ac 100644 (file)
@@ -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."));