Show
Ignore:
Timestamp:
04/14/06 13:26:50 (7 years ago)
Author:
ahu
Message:

implement stunningly cool spoofing protection, plus spoofer in dnspbench

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/pdns_recursor.cc

    r698 r699  
    128128static map<int,PacketID> d_tcpclientreadsocks, d_tcpclientwritesocks; 
    129129 
    130 MTasker<PacketID,string>* MT; 
     130typedef MTasker<PacketID,string> MT_t; 
     131MT_t* MT; 
    131132 
    132133int asendtcp(const string& data, Socket* sock)  
     
    183184    *d_len=packet.size(); 
    184185    memcpy(data,packet.c_str(),min(len,*d_len)); 
     186    if(pident.nearMisses > 100) { 
     187      L<<Logger::Error<<"Too many ("<<pident.nearMisses<<") bogus answers came in from "<<sockAddrToString((struct sockaddr_in*)toaddr, sizeof(pident.remote))<<", assuming spoof attempt."<<endl; 
     188      return -1; 
     189    } 
    185190  } 
    186191  return ret; 
     
    10001005                    L<<Logger::Warning<<"Discarding unexpected packet from "<<sockAddrToString((struct sockaddr_in*) &fromaddr, addrlen)<<endl; 
    10011006                  g_stats.unexpectedCount++; 
     1007                   
     1008                  for(MT_t::waiters_t::iterator mthread=MT->d_waiters.begin(); mthread!=MT->d_waiters.end(); ++mthread) { 
     1009                    if(!memcmp(&mthread->key.remote.sin_addr, &pident.remote.sin_addr, sizeof(pident.remote.sin_addr))) { 
     1010                      mthread->key.nearMisses++; 
     1011                    } 
     1012                  } 
    10021013                } 
    10031014              }