dns_internal.cc File Reference
#include "squid.h"
#include "base/CodeContext.h"
#include "base/InstanceId.h"
#include "base/RunnersRegistry.h"
#include "comm.h"
#include "comm/Connection.h"
#include "comm/ConnOpener.h"
#include "comm/Loops.h"
#include "comm/Read.h"
#include "comm/Write.h"
#include "dlink.h"
#include "dns/forward.h"
#include "dns/rfc3596.h"
#include "event.h"
#include "fd.h"
#include "fde.h"
#include "ip/tools.h"
#include "MemBuf.h"
#include "mgr/Registration.h"
#include "SquidConfig.h"
#include "SquidTime.h"
#include "Store.h"
#include "tools.h"
#include "util.h"
#include "wordlist.h"
#include "snmp_core.h"
#include <cerrno>
#include <random>
Include dependency graph for dns_internal.cc:

Go to the source code of this file.

Classes

class  idns_query
 
class  nsvc
 
class  ns
 
class  Dns::ConfigRr
 manage DNS internal component More...
 
struct  _sp
 

Namespaces

 Dns
 generic DNS API
 

Macros

#define _PATH_RESCONF   "/etc/resolv.conf"
 
#define NS_DEFAULTPORT   53
 
#define NS_MAXDNAME   1025
 
#define MAXDNSRCH   6
 
#define RESOLV_BUFSZ   NS_MAXDNAME * MAXDNSRCH + sizeof("search ") + 1
 
#define IDNS_MAX_TRIES   20
 
#define MAX_RCODE   17
 
#define MAX_ATTEMPT   3
 

Typedefs

typedef struct _sp sp
 

Functions

 InstanceIdDefinitions (idns_query, "dns")
 
 Dns::RunnerRegistrationEntry (ConfigRr)
 
static void idnsAddNameserver (const char *buf)
 
static void idnsAddMDNSNameservers ()
 
static void idnsAddPathComponent (const char *buf)
 
static void idnsFreeSearchpath (void)
 
static bool idnsParseNameservers (void)
 
static bool idnsParseResolvConf (void)
 
static void idnsStartQuery (idns_query *q, IDNSCB *callback, void *data)
 
static void idnsSendQuery (idns_query *q)
 
static void idnsDoSendQueryVC (nsvc *vc)
 
static int idnsFromKnownNameserver (Ip::Address const &from)
 
static idns_queryidnsFindQuery (unsigned short id)
 
static void idnsGrokReply (const char *buf, size_t sz, int from_ns)
 
static void idnsTickleQueue (void)
 
static void idnsRcodeCount (int, int)
 
static unsigned short idnsQueryID (void)
 
static void idnsSendSlaveAAAAQuery (idns_query *q)
 
static void idnsCallbackOnEarlyError (IDNSCB *callback, void *cbdata, const char *error)
 
static void idnsCheckMDNS (idns_query *q)
 
static void idnsStats (StoreEntry *sentry)
 
static void idnsSentQueryVC (const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag flag, int, void *data)
 
static void idnsInitVCConnected (const Comm::ConnectionPointer &conn, Comm::Flag status, int, void *data)
 
static void idnsVCClosed (const CommCloseCbParams &params)
 
static void idnsInitVC (size_t nsv)
 
static void idnsSendQueryVC (idns_query *q, size_t nsn)
 
static bool idnsStillPending (const idns_query *master)
 
static std::ostream & operator<< (std::ostream &os, const idns_query &answered)
 
static bool idnsCallbackOneWithAnswer (IDNSCB *callback, void *cbdata, const idns_query &answered, const bool lastAnswer)
 safely sends one set of DNS records (or an error) to the caller More...
 
static void idnsCallbackNewCallerWithOldAnswers (IDNSCB *callback, void *cbdata, const idns_query *const master)
 
static void idnsCallbackAllCallersWithNewAnswer (const idns_query *const answered, const bool lastAnswer)
 
static void idnsCallback (idns_query *q, const char *error)
 
static void idnsRead (int fd, void *)
 
static void idnsCheckQueue (void *)
 
static void idnsReadVC (const Comm::ConnectionPointer &conn, char *buf, size_t len, Comm::Flag flag, int, void *data)
 
static void idnsReadVCHeader (const Comm::ConnectionPointer &conn, char *buf, size_t len, Comm::Flag flag, int, void *data)
 
static void idnsShutdownAndFreeState (const char *reason)
 
static int idnsCachedLookup (const char *key, IDNSCB *callback, void *data)
 
void idnsALookup (const char *name, IDNSCB *callback, void *data)
 
void idnsPTRLookup (const Ip::Address &addr, IDNSCB *callback, void *data)
 
variable_listsnmp_netDnsFn (variable_list *Var, snint *ErrP)
 

Variables

static int RcodeMatrix [MAX_RCODE][MAX_ATTEMPT]
 
static const char * Rcodes []
 
static std::vector< nsnameservers
 
static spsearchpath = NULL
 
static int nns_mdns_count = 0
 
static int npc = 0
 
static int npc_alloc = 0
 
static int ndots = 1
 
static dlink_list lru_list
 
static int event_queued = 0
 
static hash_tableidns_lookup_hash = NULL
 
static OBJH idnsStats
 
static IOCB idnsReadVCHeader
 
static CNCB idnsInitVCConnected
 
static IOCB idnsReadVC
 
static IOCB idnsSentQueryVC
 
static PF idnsRead
 
static EVH idnsCheckQueue
 
static CLCB idnsVCClosed
 

Macro Definition Documentation

◆ _PATH_RESCONF

#define _PATH_RESCONF   "/etc/resolv.conf"

Definition at line 56 of file dns_internal.cc.

◆ IDNS_MAX_TRIES

#define IDNS_MAX_TRIES   20

Definition at line 75 of file dns_internal.cc.

◆ MAX_ATTEMPT

#define MAX_ATTEMPT   3

Definition at line 77 of file dns_internal.cc.

◆ MAX_RCODE

#define MAX_RCODE   17

Definition at line 76 of file dns_internal.cc.

◆ MAXDNSRCH

#define MAXDNSRCH   6

Definition at line 67 of file dns_internal.cc.

◆ NS_DEFAULTPORT

#define NS_DEFAULTPORT   53

Definition at line 59 of file dns_internal.cc.

◆ NS_MAXDNAME

#define NS_MAXDNAME   1025

Definition at line 63 of file dns_internal.cc.

◆ RESOLV_BUFSZ

#define RESOLV_BUFSZ   NS_MAXDNAME * MAXDNSRCH + sizeof("search ") + 1

Definition at line 72 of file dns_internal.cc.

Typedef Documentation

◆ sp

typedef struct _sp sp

Definition at line 80 of file dns_internal.cc.

Function Documentation

◆ idnsAddMDNSNameservers()

static void idnsAddMDNSNameservers ( )
static

◆ idnsAddNameserver()

static void idnsAddNameserver ( const char *  buf)
static

◆ idnsAddPathComponent()

static void idnsAddPathComponent ( const char *  buf)
static

Definition at line 358 of file dns_internal.cc.

References assert, buf, debugs, _sp::domain, npc, npc_alloc, safe_free, searchpath, Tolower(), and xcalloc().

Referenced by idnsParseResolvConf().

◆ idnsALookup()

◆ idnsCachedLookup()

static int idnsCachedLookup ( const char *  key,
IDNSCB callback,
void *  data 
)
static

◆ idnsCallback()

static void idnsCallback ( idns_query q,
const char *  error 
)
static

◆ idnsCallbackAllCallersWithNewAnswer()

static void idnsCallbackAllCallersWithNewAnswer ( const idns_query *const  answered,
const bool  lastAnswer 
)
static

Definition at line 1120 of file dns_internal.cc.

References CallBack(), debugs, and idns_query::master.

Referenced by idnsCallback().

◆ idnsCallbackNewCallerWithOldAnswers()

static void idnsCallbackNewCallerWithOldAnswers ( IDNSCB callback,
void *  cbdata,
const idns_query *const  master 
)
static

Definition at line 1106 of file dns_internal.cc.

References callback, idnsCallbackOneWithAnswer(), and idns_query::slave.

Referenced by idnsCachedLookup().

◆ idnsCallbackOnEarlyError()

static void idnsCallbackOnEarlyError ( IDNSCB callback,
void *  cbdata,
const char *  error 
)
static

Definition at line 1085 of file dns_internal.cc.

References callback, debugs, and error().

Referenced by idnsALookup(), and idnsPTRLookup().

◆ idnsCallbackOneWithAnswer()

static bool idnsCallbackOneWithAnswer ( IDNSCB callback,
void *  cbdata,
const idns_query answered,
const bool  lastAnswer 
)
static

◆ idnsCheckMDNS()

static void idnsCheckMDNS ( idns_query q)
static

◆ idnsCheckQueue()

◆ idnsDoSendQueryVC()

◆ idnsFindQuery()

static idns_query * idnsFindQuery ( unsigned short  id)
static

◆ idnsFreeSearchpath()

static void idnsFreeSearchpath ( void  )
static

Definition at line 387 of file dns_internal.cc.

References npc, npc_alloc, safe_free, and searchpath.

Referenced by idnsParseResolvConf(), and idnsShutdownAndFreeState().

◆ idnsFromKnownNameserver()

static int idnsFromKnownNameserver ( Ip::Address const &  from)
static

Definition at line 1010 of file dns_internal.cc.

References nameservers, and Ip::Address::port().

Referenced by idnsRead().

◆ idnsGrokReply()

◆ idnsInitVC()

◆ idnsInitVCConnected()

static void idnsInitVCConnected ( const Comm::ConnectionPointer conn,
Comm::Flag  status,
int  ,
void *  data 
)
static

◆ idnsParseNameservers()

static bool idnsParseNameservers ( void  )
static

Definition at line 394 of file dns_internal.cc.

References Config, DBG_IMPORTANT, debugs, SquidConfig::dns, and idnsAddNameserver().

Referenced by Dns::Init().

◆ idnsParseResolvConf()

static bool idnsParseResolvConf ( void  )
static

◆ idnsPTRLookup()

◆ idnsQueryID()

static unsigned short idnsQueryID ( void  )
static

◆ idnsRcodeCount()

static void idnsRcodeCount ( int  rcode,
int  attempt 
)
static

Definition at line 1523 of file dns_internal.cc.

References MAX_ATTEMPT, MAX_RCODE, and RcodeMatrix.

Referenced by idnsGrokReply().

◆ idnsRead()

◆ idnsReadVC()

◆ idnsReadVCHeader()

static void idnsReadVCHeader ( const Comm::ConnectionPointer conn,
char *  buf,
size_t  len,
Comm::Flag  flag,
int  ,
void *  data 
)
static

◆ idnsSendQuery()

◆ idnsSendQueryVC()

static void idnsSendQueryVC ( idns_query q,
size_t  nsn 
)
static

◆ idnsSendSlaveAAAAQuery()

◆ idnsSentQueryVC()

static void idnsSentQueryVC ( const Comm::ConnectionPointer conn,
char *  ,
size_t  size,
Comm::Flag  flag,
int  ,
void *  data 
)
static

◆ idnsShutdownAndFreeState()

static void idnsShutdownAndFreeState ( const char *  reason)
static

◆ idnsStartQuery()

static void idnsStartQuery ( idns_query q,
IDNSCB callback,
void *  data 
)
static

◆ idnsStats()

◆ idnsStillPending()

static bool idnsStillPending ( const idns_query master)
static
Returns
whether master or associated queries are still waiting for replies

Definition at line 1064 of file dns_internal.cc.

References assert, idns_query::master, and idns_query::slave.

Referenced by idnsCachedLookup(), and idnsCallback().

◆ idnsTickleQueue()

static void idnsTickleQueue ( void  )
static

◆ idnsVCClosed()

static void idnsVCClosed ( const CommCloseCbParams params)
static

Definition at line 872 of file dns_internal.cc.

References CommCommonCbParams::data.

◆ InstanceIdDefinitions()

InstanceIdDefinitions ( idns_query  ,
"dns"   
)

◆ operator<<()

static std::ostream& operator<< ( std::ostream &  os,
const idns_query answered 
)
static

Definition at line 1074 of file dns_internal.cc.

References idns_query::ancount, and idns_query::error.

◆ snmp_netDnsFn()

Variable Documentation

◆ event_queued

int event_queued = 0
static

Definition at line 228 of file dns_internal.cc.

Referenced by idnsCheckQueue(), and idnsTickleQueue().

◆ idns_lookup_hash

hash_table* idns_lookup_hash = NULL
static

Definition at line 229 of file dns_internal.cc.

Referenced by idnsCachedLookup(), idnsCallback(), idnsStartQuery(), and Dns::Init().

◆ idnsCheckQueue

EVH idnsCheckQueue
static

Definition at line 282 of file dns_internal.cc.

Referenced by idnsTickleQueue().

◆ idnsInitVCConnected

CNCB idnsInitVCConnected
static

Definition at line 274 of file dns_internal.cc.

Referenced by idnsInitVC().

◆ idnsRead

PF idnsRead
static

Definition at line 281 of file dns_internal.cc.

Referenced by idnsRead(), and Dns::Init().

◆ idnsReadVC

IOCB idnsReadVC
static

Definition at line 275 of file dns_internal.cc.

Referenced by idnsReadVC(), and idnsReadVCHeader().

◆ idnsReadVCHeader

IOCB idnsReadVCHeader
static

Definition at line 272 of file dns_internal.cc.

Referenced by idnsInitVCConnected(), idnsReadVC(), and idnsReadVCHeader().

◆ idnsSentQueryVC

IOCB idnsSentQueryVC
static

Definition at line 276 of file dns_internal.cc.

Referenced by idnsDoSendQueryVC().

◆ idnsStats

OBJH idnsStats
static

Definition at line 259 of file dns_internal.cc.

Referenced by Dns::Init().

◆ idnsVCClosed

CLCB idnsVCClosed
static

Definition at line 285 of file dns_internal.cc.

Referenced by idnsInitVCConnected().

◆ lru_list

◆ nameservers

◆ ndots

int ndots = 1
static

Definition at line 226 of file dns_internal.cc.

Referenced by idnsALookup(), and idnsParseResolvConf().

◆ nns_mdns_count

int nns_mdns_count = 0
static

Definition at line 223 of file dns_internal.cc.

Referenced by idnsAddMDNSNameservers(), and idnsSendQuery().

◆ npc

◆ npc_alloc

int npc_alloc = 0
static

Definition at line 225 of file dns_internal.cc.

Referenced by idnsAddPathComponent(), and idnsFreeSearchpath().

◆ RcodeMatrix

int RcodeMatrix[MAX_RCODE][MAX_ATTEMPT]
static

Definition at line 78 of file dns_internal.cc.

Referenced by idnsRcodeCount(), idnsStats(), and Dns::Init().

◆ Rcodes

const char* Rcodes[]
static
Initial value:
= {
"Success",
"Packet Format Error",
"DNS Server Failure",
"Non-Existent Domain",
"Not Implemented",
"Query Refused",
"Name Exists when it should not",
"RR Set Exists when it should not",
"RR Set that should exist does not",
"Server Not Authoritative for zone",
"Name not contained in zone",
"","","","","",
"Bad OPT Version or TSIG Signature Failure"
}

Definition at line 80 of file dns_internal.cc.

Referenced by idnsStats().

◆ searchpath

sp* searchpath = NULL
static

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors