]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2157] fix code-to-counter conversion table
authorYoshitaka Aharen <aharen@jprs.co.jp>
Thu, 15 Nov 2012 09:45:34 +0000 (18:45 +0900)
committerYoshitaka Aharen <aharen@jprs.co.jp>
Thu, 15 Nov 2012 09:45:34 +0000 (18:45 +0900)
src/bin/auth/statistics.cc.pre
src/bin/auth/statistics_items.h.pre
src/bin/auth/tests/auth_srv_unittest.cc

index 06caf62b1638d94b8db481ec6cc20d72bc1372f1..0db02b70d9d2851939f7f8db2c4cfcf3ad6bb536 100644 (file)
@@ -71,7 +71,8 @@ namespace statistics {
 
 // ### STATISTICS ITEMS DEFINITION ###
 
-const int QROpCodeToQRCounterType[16] = {
+// Note: opcode in this array must be start with 0 and be sequential
+const int opcode_to_qrcounter[] = {
     QR_OPCODE_QUERY,    // Opcode =  0: Query
     QR_OPCODE_IQUERY,   // Opcode =  1: Iquery
     QR_OPCODE_STATUS,   // Opcode =  2: STATUS
@@ -89,7 +90,11 @@ const int QROpCodeToQRCounterType[16] = {
     QR_OPCODE_OTHER,    // Opcode = 14: (Unassigned)
     QR_OPCODE_OTHER     // Opcode = 15: (Unassigned)
 };
-const int QRRCodeToQRCounterType[23] = {
+const size_t num_opcode_to_qrcounter =
+    sizeof(opcode_to_qrcounter) / sizeof(opcode_to_qrcounter[0]);
+
+// Note: rcode in this array must be start with 0 and be sequential
+const int rcode_to_qrcounter[] = {
     QR_RCODE_NOERROR,       // Rcode =  0: NoError
     QR_RCODE_FORMERR,       // Rcode =  1: FormErr
     QR_RCODE_SERVFAIL,      // Rcode =  2: ServFail
@@ -114,6 +119,8 @@ const int QRRCodeToQRCounterType[23] = {
     QR_RCODE_BADALG,        // Rcode = 21: BADALG
     QR_RCODE_BADTRUNC       // Rcode = 22: BADTRUNC
 };
+const size_t num_rcode_to_qrcounter =
+    sizeof(rcode_to_qrcounter) / sizeof(rcode_to_qrcounter[0]);
 
 Counters::Counters() :
     // size of server_qr_counter_, zone_qr_counters_: QR_COUNTER_TYPES
@@ -163,7 +170,7 @@ Counters::incRequest(const QRAttributes& qrattrs) {
     }
 
     // OPCODE
-    server_qr_counter_.inc(QROpCodeToQRCounterType[qrattrs.req_opcode_]);
+    server_qr_counter_.inc(opcode_to_qrcounter[qrattrs.req_opcode_]);
 }
 
 void
@@ -192,14 +199,9 @@ Counters::incResponse(const QRAttributes& qrattrs, const Message& response) {
 
     // RCODE
     const unsigned int rcode = response.getRcode().getCode();
-    unsigned int rcode_type = QR_RCODE_OTHER;
-    if (rcode < 23) {
-        // rcode 0..22: lookup rcode-countertype table
-        rcode_type = QRRCodeToQRCounterType[rcode];
-    } else {
-        // opcode larger than 22 is reserved or unassigned
-        rcode_type = QR_RCODE_OTHER;
-    }
+    const unsigned int rcode_type =
+        rcode < num_rcode_to_qrcounter ?
+        rcode_to_qrcounter[rcode] : QR_RCODE_OTHER;
     server_qr_counter_.inc(rcode_type);
 
     // compound attributes
index ca444ccb10ca82bcca29dddb5ccae2c56c1e2187..8145378ddfb9c75e7c0a454dafbd5a757cb44ab6 100644 (file)
@@ -30,8 +30,8 @@ struct CounterTypeTree {
 
 // ### STATISTICS ITEMS DECLARATION ###
 
-extern const int QROpCodeToQRCounterType[];
-extern const int QRRCodeToQRCounterType[];
+extern const int opcode_to_qrcounter[];
+extern const int rcode_to_qrcounter[];
 
 } // namespace statistics
 } // namespace auth
index 5a1ed4586742c58f0eec96a5d3a3f8ca30c437e9..87652d29c0d6bea805be47cc7fa84cb71afc5090 100644 (file)
@@ -1172,7 +1172,7 @@ TEST_F(AuthSrvTest, queryCounterOpcodes) {
     for (int i = 0; i < 16; ++i) {
         std::string item_name;
         int expected;
-        if (isc::auth::statistics::QROpCodeToQRCounterType[i] ==
+        if (isc::auth::statistics::opcode_to_qrcounter[i] ==
             isc::auth::statistics::QR_OPCODE_OTHER) {
             item_name = "OTHER";
             other_expected += i + 1;