* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * InspIRCd: (C) 2002-2010 InspIRCd Development Team
* See: http://wiki.inspircd.org/Credits
*
* This program is free but copyrighted software; see
}
};
+CachedQuery::CachedQuery(const std::string &res, unsigned int ttl) : data(res)
+{
+ expires = ServerInstance->Time() + ttl;
+}
+
+int CachedQuery::CalcTTLRemaining()
+{
+ int n = expires - ServerInstance->Time();
+ return (n < 0 ? 0 : n);
+}
+
/* Allocate the processing buffer */
DNSRequest::DNSRequest(DNS* dns, int rid, const std::string &original) : dnsobj(dns)
{
DNS::EmptyHeader(payload,header,length);
- if (this->dnsobj->myserver.sa.sa_family == AF_INET6)
- {
- dnsobj->myserver.in6.sin6_port = htons(DNS::QUERY_PORT);
- }
- else
- {
- dnsobj->myserver.in4.sin_port = htons(DNS::QUERY_PORT);
- }
if (ServerInstance->SE->SendTo(dnsobj, payload, length + 12, 0, &(dnsobj->myserver.sa), sa_size(dnsobj->myserver)) != length+12)
return -1;
return NULL;
/* Create an id */
- id = this->PRNG() & DNS::MAX_REQUEST_ID;
-
- /* If this id is already 'in flight', pick another. */
- while (requests[id])
- id = this->PRNG() & DNS::MAX_REQUEST_ID;
+ do {
+ id = ServerInstance->GenRandomInt(DNS::MAX_REQUEST_ID);
+ } while (requests[id]);
DNSRequest* req = new DNSRequest(this, id, original);
this->cache = new dnscache();
}
- irc::sockets::aptosa(ServerInstance->Config->DNSServer, 0, &myserver);
+ irc::sockets::aptosa(ServerInstance->Config->DNSServer, DNS::QUERY_PORT, myserver);
/* Initialize mastersocket */
- int s = irc::sockets::OpenTCPSocket(ServerInstance->Config->DNSServer, SOCK_DGRAM);
+ int s = socket(myserver.sa.sa_family, SOCK_DGRAM, 0);
this->SetFd(s);
- ServerInstance->SE->NonBlocking(this->GetFd());
/* Have we got a socket and is it nonblocking? */
if (this->GetFd() != -1)
{
+ ServerInstance->SE->SetReuse(s);
+ ServerInstance->SE->NonBlocking(s);
/* Bind the port - port 0 INADDR_ANY */
if (!ServerInstance->BindSocket(this->GetFd(), portpass, "", false))
{
*
* -- Thanks jilles for pointing this one out.
*/
- irc::sockets::sockaddrs expect_src;
- irc::sockets::aptosa(ServerInstance->Config->DNSServer, DNS::QUERY_PORT, &expect_src);
-
- if (memcmp(&from, &expect_src, sizeof(irc::sockets::sockaddrs)))
+ if (memcmp(&from, &myserver, sizeof(irc::sockets::sockaddrs)))
{
return DNSResult(-1,"",0,"");
}
}
}
}
-
-/** Generate pseudo-random number */
-unsigned long DNS::PRNG()
-{
- unsigned long val = 0;
- timeval n;
- serverstats* s = ServerInstance->stats;
- gettimeofday(&n,NULL);
- val = (n.tv_usec ^ (getpid() ^ geteuid()) ^ ((this->currid++)) ^ s->statsAccept) + n.tv_sec;
- val = val + (s->statsCollisions ^ s->statsDnsGood) - s->statsDnsBad;
- val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv) - ServerInstance->ports.size();
- return val;
-}