dns_internal.cc File Reference
#include "squid.h"
#include "base/CodeContext.h"
#include "base/InstanceId.h"
#include "base/Random.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 "debug/Messages.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 "snmp_agent.h"
#include "SquidConfig.h"
#include "Store.h"
#include "tools.h"
#include "util.h"
#include "wordlist.h"
#include "snmp_core.h"
#include <cerrno>
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

namespace  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")
 
 DefineRunnerRegistratorIn (Dns, 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 = nullptr
 
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 = nullptr
 
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 57 of file dns_internal.cc.

◆ IDNS_MAX_TRIES

#define IDNS_MAX_TRIES   20

Definition at line 76 of file dns_internal.cc.

◆ MAX_ATTEMPT

#define MAX_ATTEMPT   3

Definition at line 78 of file dns_internal.cc.

◆ MAX_RCODE

#define MAX_RCODE   17

Definition at line 77 of file dns_internal.cc.

◆ MAXDNSRCH

#define MAXDNSRCH   6

Definition at line 68 of file dns_internal.cc.

◆ NS_DEFAULTPORT

#define NS_DEFAULTPORT   53

Definition at line 60 of file dns_internal.cc.

◆ NS_MAXDNAME

#define NS_MAXDNAME   1025

Definition at line 64 of file dns_internal.cc.

◆ RESOLV_BUFSZ

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

Definition at line 73 of file dns_internal.cc.

Typedef Documentation

◆ sp

typedef struct _sp sp

Definition at line 101 of file dns_internal.cc.

Function Documentation

◆ DefineRunnerRegistratorIn()

DefineRunnerRegistratorIn ( Dns  ,
ConfigRr   
)

◆ idnsAddMDNSNameservers()

static void idnsAddMDNSNameservers ( )
static

◆ idnsAddNameserver()

static void idnsAddNameserver ( const char *  buf)
static

◆ idnsAddPathComponent()

static void idnsAddPathComponent ( const char *  buf)
static

Definition at line 359 of file dns_internal.cc.

References assert, 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 1125 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 1111 of file dns_internal.cc.

References idnsCallbackOneWithAnswer(), and idns_query::slave.

Referenced by idnsCachedLookup().

◆ idnsCallbackOnEarlyError()

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

Definition at line 1090 of file dns_internal.cc.

References 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 388 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 1015 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 395 of file dns_internal.cc.

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

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 1528 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 1069 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

◆ InstanceIdDefinitions()

InstanceIdDefinitions ( idns_query  ,
"dns"   
)

◆ operator<<()

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

Definition at line 1079 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 229 of file dns_internal.cc.

Referenced by idnsCheckQueue(), and idnsTickleQueue().

◆ idns_lookup_hash

hash_table* idns_lookup_hash = nullptr
static

Definition at line 230 of file dns_internal.cc.

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

◆ idnsCheckQueue

EVH idnsCheckQueue
static

Definition at line 283 of file dns_internal.cc.

Referenced by idnsTickleQueue().

◆ idnsInitVCConnected

CNCB idnsInitVCConnected
static

Definition at line 275 of file dns_internal.cc.

Referenced by idnsInitVC().

◆ idnsRead

PF idnsRead
static

Definition at line 282 of file dns_internal.cc.

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

◆ idnsReadVC

IOCB idnsReadVC
static

Definition at line 276 of file dns_internal.cc.

Referenced by idnsReadVC(), and idnsReadVCHeader().

◆ idnsReadVCHeader

IOCB idnsReadVCHeader
static

Definition at line 273 of file dns_internal.cc.

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

◆ idnsSentQueryVC

IOCB idnsSentQueryVC
static

Definition at line 277 of file dns_internal.cc.

Referenced by idnsDoSendQueryVC().

◆ idnsStats

OBJH idnsStats
static

Definition at line 260 of file dns_internal.cc.

Referenced by Dns::Init().

◆ idnsVCClosed

CLCB idnsVCClosed
static

Definition at line 286 of file dns_internal.cc.

Referenced by idnsInitVCConnected().

◆ lru_list

◆ nameservers

◆ ndots

int ndots = 1
static

Definition at line 227 of file dns_internal.cc.

Referenced by idnsALookup(), and idnsParseResolvConf().

◆ nns_mdns_count

int nns_mdns_count = 0
static

Definition at line 224 of file dns_internal.cc.

Referenced by idnsAddMDNSNameservers(), and idnsSendQuery().

◆ npc

◆ npc_alloc

int npc_alloc = 0
static

Definition at line 226 of file dns_internal.cc.

Referenced by idnsAddPathComponent(), and idnsFreeSearchpath().

◆ RcodeMatrix

int RcodeMatrix[MAX_RCODE][MAX_ATTEMPT]
static

Definition at line 79 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 81 of file dns_internal.cc.

Referenced by idnsStats().

◆ searchpath

sp* searchpath = nullptr
static

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors