From f6007449e1f52abd75b45043ae6d823b4be42dee Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Mon, 8 Jan 2018 16:09:45 +0100 Subject: [PATCH] Store rcodes as unsigned --- pdns/dns.cc | 4 ++-- pdns/dns.hh | 4 ++-- pdns/dnsdist-lua-actions.cc | 6 +++--- pdns/dnsdist-lua-rules.cc | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pdns/dns.cc b/pdns/dns.cc index b04a03257..71f2c0e76 100644 --- a/pdns/dns.cc +++ b/pdns/dns.cc @@ -57,13 +57,13 @@ std::vector RCode::rcodes_s = boost::assign::list_of ("Bad/missing Server Cookie") ; -std::string RCode::to_s(unsigned short rcode) { +std::string RCode::to_s(uint8_t rcode) { if (rcode > RCode::rcodes_s.size()-1 ) return std::string("Err#")+std::to_string(rcode); return RCode::rcodes_s[rcode]; } -std::string ERCode::to_s(unsigned short rcode) { +std::string ERCode::to_s(uint8_t rcode) { return RCode::to_s(rcode); } diff --git a/pdns/dns.hh b/pdns/dns.hh index 9f75ba4a4..8ea94c8e7 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -57,7 +57,7 @@ class RCode { public: enum rcodes_ { NoError=0, FormErr=1, ServFail=2, NXDomain=3, NotImp=4, Refused=5, YXDomain=6, YXRRSet=7, NXRRSet=8, NotAuth=9, NotZone=10}; - static std::string to_s(unsigned short rcode); + static std::string to_s(uint8_t rcode); static std::vector rcodes_s; }; @@ -65,7 +65,7 @@ class ERCode { public: enum rcodes_ { BADVERS=16, BADSIG=16, BADKEY=17, BADTIME=18, BADMODE=19, BADNAME=20, BADALG=21, BADTRUNC=22, BADCOOKIE=23 }; - static std::string to_s(unsigned short rcode); + static std::string to_s(uint8_t rcode); }; class Opcode diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index 2c6e13752..b5c245ca0 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -275,7 +275,7 @@ private: class RCodeAction : public DNSAction { public: - RCodeAction(int rcode) : d_rcode(rcode) {} + RCodeAction(uint8_t rcode) : d_rcode(rcode) {} DNSAction::Action operator()(DNSQuestion* dq, string* ruleresult) const override { dq->dh->rcode = d_rcode; @@ -288,7 +288,7 @@ public: } private: - int d_rcode; + uint8_t d_rcode; }; class TCAction : public DNSAction @@ -941,7 +941,7 @@ void setupLuaActions() return std::shared_ptr(new LogAction(fname, binary ? *binary : true, append ? *append : false, buffered ? *buffered : false)); }); - g_lua.writeFunction("RCodeAction", [](int rcode) { + g_lua.writeFunction("RCodeAction", [](uint8_t rcode) { return std::shared_ptr(new RCodeAction(rcode)); }); diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index 92c89e41a..9128b2293 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -724,7 +724,7 @@ private: class RCodeRule : public DNSRule { public: - RCodeRule(int rcode) : d_rcode(rcode) + RCodeRule(uint8_t rcode) : d_rcode(rcode) { } bool matches(const DNSQuestion* dq) const override @@ -736,13 +736,13 @@ public: return "rcode=="+RCode::to_s(d_rcode); } private: - int d_rcode; + uint8_t d_rcode; }; class ERCodeRule : public DNSRule { public: - ERCodeRule(int rcode) : d_rcode(rcode & 0xF), d_extrcode(rcode >> 4) + ERCodeRule(uint8_t rcode) : d_rcode(rcode & 0xF), d_extrcode(rcode >> 4) { } bool matches(const DNSQuestion* dq) const override @@ -781,8 +781,8 @@ public: return "ercode=="+ERCode::to_s(d_rcode | (d_extrcode << 4)); } private: - int d_rcode; // plain DNS Rcode - int d_extrcode; // upper bits in EDNS0 record + uint8_t d_rcode; // plain DNS Rcode + uint8_t d_extrcode; // upper bits in EDNS0 record }; class RDRule : public DNSRule @@ -1207,11 +1207,11 @@ void setupLuaRules() return std::shared_ptr(new QNameWireLengthRule(min, max)); }); - g_lua.writeFunction("RCodeRule", [](int rcode) { + g_lua.writeFunction("RCodeRule", [](uint8_t rcode) { return std::shared_ptr(new RCodeRule(rcode)); }); - g_lua.writeFunction("ERCodeRule", [](int rcode) { + g_lua.writeFunction("ERCodeRule", [](uint8_t rcode) { return std::shared_ptr(new ERCodeRule(rcode)); }); -- 2.40.0