Changeset 1309

Show
Ignore:
Timestamp:
11/27/08 16:47:02 (4 years ago)
Author:
ahu
Message:

send Lua the 'local' address too

Location:
trunk/pdns/pdns
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/docs/pdns.sgml

    r1308 r1309  
    88448844        <para> 
    88458845          Both functions are passed the IP address of the requestor, plus the name and type being requested. In return, these functions indicate if they 
    8846           have taken over the request, or want to let normal proceedings take their course. 
     8846          have taken over the request, or want to let normal proceedings take their course. Beyond version 3.1.7, the IP address on which the question was received 
     8847          is inserted immediately after the IP address of the requestor - so in that case there are 4 parameters. 
    88478848        </para> 
    88488849        <para> 
  • trunk/pdns/pdns/lua-pdns-recursor.cc

    r1206 r1309  
    1010} 
    1111 
    12 bool PowerDNSLua::nxdomain(const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
     12bool PowerDNSLua::nxdomain(const ComboAddress& remote,const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
    1313{ 
    1414  return false; 
    1515} 
    1616 
    17 bool PowerDNSLua::preresolve(const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
     17bool PowerDNSLua::preresolve(const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
    1818{ 
    1919  return false; 
     
    114114} 
    115115 
    116 bool PowerDNSLua::nxdomain(const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
    117 { 
    118   return passthrough("nxdomain", remote, query, qtype, ret, res); 
    119 } 
    120  
    121 bool PowerDNSLua::preresolve(const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
    122 { 
    123   return passthrough("preresolve", remote, query, qtype, ret, res); 
     116bool PowerDNSLua::nxdomain(const ComboAddress& remote, const ComboAddress& local,const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
     117{ 
     118  return passthrough("nxdomain", remote, local, query, qtype, ret, res); 
     119} 
     120 
     121bool PowerDNSLua::preresolve(const ComboAddress& remote, const ComboAddress& local,const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
     122{ 
     123  return passthrough("preresolve", remote, local, query, qtype, ret, res); 
    124124} 
    125125 
     
    154154 
    155155 
    156 bool PowerDNSLua::passthrough(const string& func, const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
     156bool PowerDNSLua::passthrough(const string& func, const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res) 
    157157{ 
    158158  lua_getglobal(d_lua,  func.c_str()); 
     
    164164  /* the first argument */ 
    165165  lua_pushstring(d_lua,  remote.toString().c_str() ); 
     166  lua_pushstring(d_lua,  local.toString().c_str() ); 
    166167  lua_pushstring(d_lua,  query.c_str() ); 
    167168  lua_pushnumber(d_lua,  qtype.getCode() ); 
    168169 
    169   if(lua_pcall(d_lua,  3, 2, 0)) { // error  
    170     string error=string("lua error: ")+lua_tostring(d_lua, -1); 
     170  if(lua_pcall(d_lua,  4, 2, 0)) { // error  
     171    string error=string("lua error in '"+func+"': ")+lua_tostring(d_lua, -1); 
    171172    lua_pop(d_lua, 1); 
    172173    throw runtime_error(error); 
  • trunk/pdns/pdns/lua-pdns-recursor.hh

    r1200 r1309  
    1212  ~PowerDNSLua(); 
    1313  void reload(); 
    14   bool preresolve(const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret); 
    15   bool nxdomain(const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret); 
     14  bool preresolve(const ComboAddress& remote,const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret); 
     15  bool nxdomain(const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret); 
    1616private: 
    1717  lua_State* d_lua; 
    18   bool passthrough(const string& func, const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res); 
     18  bool passthrough(const string& func, const ComboAddress& remote,const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res); 
    1919  bool getFromTable(const std::string& key, std::string& value); 
    2020  bool getFromTable(const std::string& key, uint32_t& value); 
  • trunk/pdns/pdns/pdns_recursor.cc

    r1286 r1309  
    8585g_tcpListenSockets_t g_tcpListenSockets; 
    8686int g_tcpTimeout; 
    87  
     87map<int, ComboAddress> g_listenSocketsAddresses; 
    8888struct DNSComboWriter { 
    8989  DNSComboWriter(const char* data, uint16_t len, const struct timeval& now) : d_mdp(data, len), d_now(now), d_tcp(false), d_socket(-1) 
     
    540540    int res; 
    541541 
    542     if(!g_pdl.get() || !g_pdl->preresolve(dc->d_remote, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res)) { 
     542    if(!g_pdl.get() || !g_pdl->preresolve(dc->d_remote, g_listenSocketsAddresses[dc->d_socket], dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res)) { 
    543543       res = sr.beginResolve(dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), dc->d_mdp.d_qclass, ret); 
    544544 
    545545       if(g_pdl.get()) { 
    546546         if(res == RCode::NXDomain) 
    547            g_pdl->nxdomain(dc->d_remote, dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res); 
     547           g_pdl->nxdomain(dc->d_remote, g_listenSocketsAddresses[dc->d_socket], dc->d_mdp.d_qname, QType(dc->d_mdp.d_qtype), ret, res); 
    548548       } 
    549549    } 
     
    10481048     
    10491049    Utility::setNonBlocking(fd); 
    1050     //    g_fdm->addReadFD(fd, handleNewUDPQuestion); 
     1050 
    10511051    deferredAdd.push_back(make_pair(fd, handleNewUDPQuestion)); 
    1052  
     1052    g_listenSocketsAddresses[fd]=sin; 
    10531053    if(sin.sin4.sin_family == AF_INET)  
    10541054      L<<Logger::Error<<"Listening for UDP queries on "<< sin.toString() <<":"<<st.port<<endl;