diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2011-06-06 16:41:55 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2011-06-06 16:41:55 +0200 |
commit | 2b9e5ac193ea91817ff17851a4a16a42a5b87fdb (patch) | |
tree | 207ffb12ed68bc729ac9809b69cc00552c598037 /runtime/nsd_ptcp.c | |
parent | 223b103ccca416effbed2d61798e4aad7d421cc3 (diff) | |
download | rsyslog-2b9e5ac193ea91817ff17851a4a16a42a5b87fdb.tar.gz rsyslog-2b9e5ac193ea91817ff17851a4a16a42a5b87fdb.tar.xz rsyslog-2b9e5ac193ea91817ff17851a4a16a42a5b87fdb.zip |
added a first implementation of a DNS name cache
this still has a couple of weaknesses, like no size limit, no expiration
of entries, suboptimal algorithms -- but it should perform better than
what we had previously. Implementation will be improved based on
feedback during the next couple of releases
Diffstat (limited to 'runtime/nsd_ptcp.c')
-rw-r--r-- | runtime/nsd_ptcp.c | 34 |
1 files changed, 2 insertions, 32 deletions
diff --git a/runtime/nsd_ptcp.c b/runtime/nsd_ptcp.c index dd6764fa..7dd489e9 100644 --- a/runtime/nsd_ptcp.c +++ b/runtime/nsd_ptcp.c @@ -50,6 +50,7 @@ #include "nsdsel_ptcp.h" #include "nsdpoll_ptcp.h" #include "nsd_ptcp.h" +#include "dnscache.h" MODULE_TYPE_LIB MODULE_TYPE_NOKEEP @@ -260,38 +261,7 @@ FillRemHost(nsd_ptcp_t *pThis, struct sockaddr *pAddr) ISOBJ_TYPE_assert(pThis, nsd_ptcp); assert(pAddr != NULL); - error = getnameinfo(pAddr, SALEN(pAddr), (char*)szIP, sizeof(szIP), NULL, 0, NI_NUMERICHOST); - - if(error) { - dbgprintf("Malformed from address %s\n", gai_strerror(error)); - strcpy((char*)szHname, "???"); - strcpy((char*)szIP, "???"); - ABORT_FINALIZE(RS_RET_INVALID_HNAME); - } - - if(!glbl.GetDisableDNS()) { - error = getnameinfo(pAddr, SALEN(pAddr), (char*)szHname, NI_MAXHOST, NULL, 0, NI_NAMEREQD); - if(error == 0) { - memset (&hints, 0, sizeof (struct addrinfo)); - hints.ai_flags = AI_NUMERICHOST; - hints.ai_socktype = SOCK_STREAM; - /* we now do a lookup once again. This one should fail, - * because we should not have obtained a non-numeric address. If - * we got a numeric one, someone messed with DNS! - */ - if(getaddrinfo((char*)szHname, NULL, &hints, &res) == 0) { - freeaddrinfo (res); - /* OK, we know we have evil, so let's indicate this to our caller */ - snprintf((char*)szHname, NI_MAXHOST, "[MALICIOUS:IP=%s]", szIP); - dbgprintf("Malicious PTR record, IP = \"%s\" HOST = \"%s\"", szIP, szHname); - iRet = RS_RET_MALICIOUS_HNAME; - } - } else { - strcpy((char*)szHname, (char*)szIP); - } - } else { - strcpy((char*)szHname, (char*)szIP); - } + CHKiRet(dnscacheLookup(pAddr, szHname, szIP)); /* We now have the names, so now let's allocate memory and store them permanently. * (side note: we may hold on to these values for quite a while, thus we trim their |