From: Yoshitaka Aharen Date: Thu, 15 Nov 2012 09:45:34 +0000 (+0900) Subject: [2157] fix code-to-counter conversion table X-Git-Tag: bind10-1.1.0beta1-release~85^2~5^2~110 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e784ad2b33879f2cfcb40921a891fb73714be68;p=thirdparty%2Fkea.git [2157] fix code-to-counter conversion table --- diff --git a/src/bin/auth/statistics.cc.pre b/src/bin/auth/statistics.cc.pre index 06caf62b16..0db02b70d9 100644 --- a/src/bin/auth/statistics.cc.pre +++ b/src/bin/auth/statistics.cc.pre @@ -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 diff --git a/src/bin/auth/statistics_items.h.pre b/src/bin/auth/statistics_items.h.pre index ca444ccb10..8145378ddf 100644 --- a/src/bin/auth/statistics_items.h.pre +++ b/src/bin/auth/statistics_items.h.pre @@ -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 diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc index 5a1ed45867..87652d29c0 100644 --- a/src/bin/auth/tests/auth_srv_unittest.cc +++ b/src/bin/auth/tests/auth_srv_unittest.cc @@ -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;