Skip to content

Commit

Permalink
Added enum namespace to lua-pdns to prevent magic number usage when r…
Browse files Browse the repository at this point in the history
…eferring to pdns_recursor return types for pdns.DROP and pdns.PASS
  • Loading branch information
Zack Allen committed Jan 6, 2014
1 parent 8501bb0 commit 92c0733
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pdns/lua-pdns.cc
Expand Up @@ -299,9 +299,9 @@ PowerDNSLua::PowerDNSLua(const std::string& fname)
// set syslog codes used by Logger/enum Urgency
pushSyslogSecurityLevelTable(d_lua);
lua_setfield(d_lua, -2, "loglevels");
lua_pushnumber(d_lua, -1);
lua_pushnumber(d_lua, RecursorBehavior::PASS);
lua_setfield(d_lua, -2, "PASS");
lua_pushnumber(d_lua, -2);
lua_pushnumber(d_lua, RecursorBehavior::DROP);
lua_setfield(d_lua, -2, "DROP");

lua_setglobal(d_lua, "pdns");
Expand Down
3 changes: 2 additions & 1 deletion pdns/lua-pdns.hh
Expand Up @@ -30,7 +30,8 @@ protected: // FIXME?
bool d_variable;
ComboAddress d_local;
};

// this enum creates constants to track the pdns_recursor behavior when returned from the Lua call
namespace RecursorBehavior { enum returnTypes{PASS=-1,DROP=-2}; };
void pushResourceRecordsTable(lua_State* lua, const vector<DNSResourceRecord>& records);
void popResourceRecordsTable(lua_State *lua, const string &query, vector<DNSResourceRecord>& ret);
void pushSyslogSecurityLevelTable(lua_State *lua);
Expand Down
2 changes: 0 additions & 2 deletions pdns/lua-recursor.hh
Expand Up @@ -13,9 +13,7 @@ public:
bool nxdomain(const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret, bool* variable);
bool nodata(const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret, bool* variable);
bool postresolve(const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret, bool* variable);

private:
bool passthrough(const string& func, const ComboAddress& remote,const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res, bool* variable);
};

#endif
6 changes: 3 additions & 3 deletions pdns/pdns_recursor.cc
Expand Up @@ -563,12 +563,12 @@ void startDoResolve(void *p)
}
}

if(res == -2) {
if(res == RecursorBehavior::DROP) {
delete dc;
dc=0;
return;
}
if(tracedQuery || res < 0 || res == RCode::ServFail || pw.getHeader()->rcode == RCode::ServFail)
if(tracedQuery || res == RecursorBehavior::PASS || res == RCode::ServFail || pw.getHeader()->rcode == RCode::ServFail)
{
string trace(sr.getTrace());
if(!trace.empty()) {
Expand All @@ -581,7 +581,7 @@ void startDoResolve(void *p)
}
}

if(res < 0) {
if(res == RecursorBehavior::PASS) {
pw.getHeader()->rcode=RCode::ServFail;
// no commit here, because no record
g_stats.servFails++;
Expand Down

0 comments on commit 92c0733

Please sign in to comment.