130 if (hptr ==
nullptr) {
139 next(e ? e->hosts : nullptr),
166 for (
auto **X = &n->
hosts; *X; X = &(*X)->next) {
190 for (x = n->
hosts; x; x = next) {
213 if ((*n1)->last_use_time > (*n2)->last_use_time)
216 if ((*n1)->last_use_time < (*n2)->last_use_time)
233 assert(list_count < netdbEntry::UseCount());
234 *(list + list_count) = n;
243 for (k = 0; k < list_count; ++k) {
284 char *hostname =
nullptr;
309 debugs(38, 3,
"netdbSendPing: " << hostname <<
" moved from " << n->
network <<
" to " << na->
network);
314 debugs(38,
DBG_IMPORTANT,
"ERROR: Squid BUG: net_db_name list bug: " << hostname <<
" not found");
320 for (X = &n->
hosts; *X; X = &(*X)->
next) {
338 debugs(38, 3,
"netdbSendPing: pinging " << hostname);
358 debugs(14, 5,
"networkFromInaddr : Masked IPv6 Address to " << in <<
"/64 routing part.");
362 debugs(14, 5,
"networkFromInaddr : Masked IPv4 Address to " << out <<
"/24.");
366 debugs(14, 5,
"networkFromInaddr : Masked IPv4 Address to " << in <<
"/24.");
377 if ((*n1)->rtt > (*n2)->rtt)
379 else if ((*n1)->rtt < (*n2)->rtt)
391 for (i = 0; i < n->
n_peers; ++i, ++p) {
420 for (i = 0; i < osize; ++i)
421 *(n->
peers + i) = *(o + i);
442 else if (p1->
rtt < p2->
rtt)
507 count <<
" entries, " <<
540 if (fstat(fd, &sb) < 0) {
546 char *buf = (
char *)
xcalloc(1, sb.st_size + 1);
556 while ((s = strchr(t,
'\n'))) {
573 if ((q = strtok(
nullptr,
w_space)) ==
nullptr)
578 if ((q = strtok(
nullptr,
w_space)) ==
nullptr)
591 if ((q = strtok(
nullptr,
w_space)) ==
nullptr)
596 if ((q = strtok(
nullptr,
w_space)) ==
nullptr)
601 if ((q = strtok(
nullptr,
w_space)) ==
nullptr)
606 if ((q = strtok(
nullptr,
w_space)) ==
nullptr)
617 while ((q = strtok(
nullptr,
w_space)) !=
nullptr) {
630 count <<
" entries, " <<
640 if (!strcmp(w->
key, name))
654 struct in_addr line_addr;
661 rec_sz += 1 +
sizeof(
struct in_addr);
662 rec_sz += 1 +
sizeof(
int);
663 rec_sz += 1 +
sizeof(
int);
665 Assure(rec_sz <= ex->parsingBuffer.capacity());
666 debugs(38, 3,
"netdbExchangeHandleReply: " << receivedData.
length <<
" read bytes");
669 debugs(38, 3,
"netdbExchangeHandleReply: Peer became invalid");
674 debugs(38, 3,
"for " << *ex->
p);
684 debugs(38, 3,
"reply status " << scode);
699 debugs(38, 5,
"netdbExchangeHandleReply: start parsing loop, size = " <<
size);
701 while (
size >= rec_sz) {
702 debugs(38, 5,
"netdbExchangeHandleReply: in parsing loop, size = " <<
size);
707 for (o = 0; o < rec_sz;) {
708 switch ((
int) *(p + o)) {
713 memcpy(&line_addr, p + o,
sizeof(
struct in_addr));
715 o +=
sizeof(
struct in_addr);
720 memcpy(&j, p + o,
sizeof(
int));
722 rtt = (
double) ntohl(j) / 1000.0;
727 memcpy(&j, p + o,
sizeof(
int));
729 hops = (
double) ntohl(j) / 1000.0;
754 debugs(38, 3,
"netdbExchangeHandleReply: size left over in this buffer: " <<
size <<
" bytes");
756 debugs(38, 3,
"netdbExchangeHandleReply: used " << nused <<
757 " entries, (x " << rec_sz <<
" bytes) == " << nused * rec_sz <<
761 debugs(38, 3,
"netdbExchangeHandleReply: ENTRY_ABORTED");
768 debugs(38, 2,
"discarding a partially received record due to Store EOF: " << leftoverBytes);
778 Assure(remainingSpace.length);
833 debugs(38, 3,
"netdbHandlePingReply: from " << from);
846 n->
hops = ((n->
hops * (N - 1)) + hops) / N;
848 n->
rtt = ((n->
rtt * (N - 1)) + rtt) / N;
850 debugs(38, 3,
"netdbHandlePingReply: " << n->
network <<
"; rtt="<<
851 std::setw(5)<< std::setprecision(2) << n->
rtt <<
" hops="<<
852 std::setw(4) << n->
hops);
887 if (i != netdbEntry::UseCount())
889 ", expected " << netdbEntry::UseCount());
896 for (k = 0; k < i; ++k) {
912 for (j = 0; j < n->
n_peers; ++j, ++p) {
935 return (
int) (n->
hops + 0.5);
951 return (
int) (n->
rtt + 0.5);
971 *rtt = (
int) (n->
rtt + 0.5);
990 double rtt = (
double) irtt;
991 double hops = (
double) ihops;
993 debugs(38, 3, url.
host() <<
", " << ihops <<
" hops, " << irtt <<
" rtt");
997 debugs(38, 3,
"host " << url.
host() <<
" not found");
1013 qsort((
char *) n->
peers,
1032 debugs(38, 5,
"netdbExchangeUpdatePeer: '" << addr <<
"', "<<
1033 std::setfill(
'0')<< std::setprecision(2) << hops <<
" hops, " <<
1037 debugs(38, 5,
"netdbExchangeUpdatePeer: Aborting peer update for '" << addr <<
"', NetDB cannot handle IPv6.");
1060 qsort((
char *) n->
peers,
1104 struct in_addr line_addr;
1109 rec_sz += 1 +
sizeof(
struct in_addr);
1110 rec_sz += 1 +
sizeof(
int);
1111 rec_sz += 1 +
sizeof(
int);
1130 if (i + rec_sz > 4096) {
1139 memcpy(&buf[i], &line_addr,
sizeof(
struct in_addr));
1141 i +=
sizeof(
struct in_addr);
1146 j = htonl((
int) (n->
rtt * 1000));
1148 memcpy(&buf[i], &j,
sizeof(
int));
1155 j = htonl((
int) (n->
hops * 1000));
1157 memcpy(&buf[i], &j,
sizeof(
int));
1185 static const SBuf netDB(
"netdb");
1187 debugs(38, 3,
"Requesting '" << uri <<
"'");
1188 const auto mx = MasterXaction::MakePortless<XactionInitiator::initIcmp>();
1222 const auto p = peer.get();
1225 if (strcasecmp(p->host, hostname) != 0)
1275 for (i = 0; i < n->
n_peers; ++i) {
#define Assure(condition)
const CachePeers & CurrentCachePeers()
void(void *, StoreIOBuffer) STCB
#define CBDATA_CLASS_INIT(type)
void host(const char *src)
void userInfo(const SBuf &s)
Security::PeerOptions secure
security settings for peer connection
Cbc * valid() const
was set and is valid
Cbc * get() const
a temporary valid raw Cbc pointer or NULL
const Ip::Address & current() const
encapsulates DNS lookup results
static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *)
Same as Start() but no master xaction info (AccessLogEntry) available.
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
static HttpRequest * FromUrlXXX(const char *url, const MasterXaction::Pointer &, const HttpRequestMethod &method=Http::METHOD_GET)
AnyP::Uri url
the request URI
AnyP::ProtocolVersion http_ver
Http::StatusCode status() const
retrieve the status code for this status line
void DomainPing(Ip::Address &to, const char *domain)
char * toStr(char *buf, const unsigned int blen, int force=AF_UNSPEC) const
bool getInAddr(struct in_addr &) const
int applyMask(const Address &mask)
void setAnyAddr()
NOTE: Does NOT clear the Port stored. Only the Address and Type.
const HttpReply & baseReply() const
bool encryptTransport
whether transport encryption (TLS/SSL) is to be used on connections to the peer
struct SquidConfig::@89 Netdb
int unlock(const char *context)
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
void append(char const *, int) override
Appends a c-string to existing packed data.
StoreIOBuffer & positionAt(const int64_t newOffset)
convenience method for changing the offset of a being-configured buffer
struct StoreIOBuffer::@123 flags
void consume(size_t)
get rid of previously appended() prefix of a given size
const char * c_str()
a NUL-terminated version of content(); same lifetime as content()
size_t contentSize() const
the total number of append()ed bytes that were not consume()d
StoreIOBuffer makeInitialSpace()
void appended(const char *, size_t)
remember the new bytes received into the previously provided space()
net_db_name(const char *name, netdbEntry *)
netdbEntry * net_db_entry
const char * peername
associated CachePeer::host (i.e. cache_peer hostname, not name=value!)
char network[MAX_IPSTRLEN]
CBDATA_CLASS(netdbExchangeState)
CbcPointer< CachePeer > p
netdb_conn_state_t connstate
netdbExchangeState(CachePeer *aPeer, const HttpRequestPointer &theReq)
Store::ParsingBuffer parsingBuffer
for receiving a NetDB reply body from Store and interpreting it
#define debugs(SECTION, LEVEL, CONTENT)
#define EBIT_TEST(flag, bit)
void eventAddIsh(const char *name, EVH *func, void *arg, double delta_ish, int weight)
int FD_READ_METHOD(int fd, char *buf, int len)
int file_open(const char *path, int mode)
const ipcache_addrs * ipcache_gethostbyname(const char *name, int flags)
void ipcache_nbgethostbyname(const char *name, IPH *handler, void *handlerData)
hash_link * hash_lookup(hash_table *, const void *)
hash_table * hash_create(HASHCMP *, int, HASHHASH *)
int HASHCMP(const void *, const void *)
hash_link * hash_next(hash_table *)
void hash_first(hash_table *)
void hash_join(hash_table *, hash_link *)
void hash_remove_link(hash_table *, hash_link *)
const char * hashKeyStr(const hash_link *)
char * internalRemoteUri(bool encrypt, const char *host, unsigned short port, const char *dir, const SBuf &name)
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
void IPH(const ipcache_addrs *, const Dns::LookupDetails &details, void *)
void logfileClose(Logfile *lf)
void logfilePrintf(Logfile *lf, const char *fmt,...)
Logfile * logfileOpen(const char *path, size_t bufsz, int fatal_flag)
void memFree(void *, int type)
Free a element allocated by memAllocate()
void * memAllocate(mem_type)
Allocate one element from the typed pool.
AnyP::ProtocolVersion ProtocolVersion()
void RegisterAction(char const *action, char const *desc, OBJH *handler, Protected, Atomic, Format)
int peerHTTPOkay(const CachePeer *p, PeerSelector *ps)
peer_t neighborType(const CachePeer *p, const AnyP::Uri &url)
static void netdbHashInsert(netdbEntry *n, Ip::Address &addr)
static void netdbRelease(netdbEntry *n)
void netdbPingSite(const char *hostname)
void netdbHostData(const char *host, int *samp, int *rtt, int *hops)
static void netdbHashDelete(const char *key)
void netdbDump(StoreEntry *sentry)
static void netdbSaveState(void *)
int netdbHostHops(const char *host)
int netdbHostRtt(const char *host)
static STCB netdbExchangeHandleReply
static netdbEntry * netdbLookupHost(const char *key)
static net_db_peer * netdbPeerByName(const netdbEntry *n, const char *)
void netdbExchangeUpdatePeer(Ip::Address &addr, CachePeer *e, double rtt, double hops)
static netdbEntry * netdbAdd(Ip::Address &addr)
static void netdbPurgeLRU(void)
static void netdbHostInsert(netdbEntry *n, const char *hostname)
static netdbEntry * netdbLookupAddr(const Ip::Address &addr)
static void netdbHostDelete(const net_db_name *x)
static hash_table * host_table
static void netdbReloadState(void)
static hash_table * addr_table
void netdbUpdatePeer(const AnyP::Uri &url, CachePeer *e, int irtt, int ihops)
void netdbDeleteAddrNetwork(Ip::Address &addr)
static wordlist * peer_names
static CachePeer * findUsableParentAtHostname(PeerSelector *ps, const char *const hostname, const HttpRequest &request)
static const char * netdbPeerName(const char *name)
void netdbBinaryExchange(StoreEntry *s)
static int sortPeerByRtt(const void *A, const void *B)
static net_db_peer * netdbPeerAdd(netdbEntry *n, CachePeer *e)
static int sortByRtt(const void *A, const void *B)
static Ip::Address networkFromInaddr(const Ip::Address &a)
CachePeer * netdbClosestParent(PeerSelector *ps)
void netdbHandlePingReply(const Ip::Address &from, int hops, int rtt)
void netdbExchangeStart(void *data)
static int netdbLRU(const void *A, const void *B)
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
int storeUnregister(store_client *sc, StoreEntry *e, void *data)
void storeClientCopy(store_client *sc, StoreEntry *e, StoreIOBuffer copyInto, STCB *callback, void *data)
store_client * storeClientListAdd(StoreEntry *e, void *data)
time_t getCurrentTime() STUB_RETVAL(0) int tvSubUsec(struct timeval
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
int tvSubMsec(struct timeval t1, struct timeval t2)
const char * wordlistAdd(wordlist **list, const char *key)
void * xcalloc(size_t n, size_t sz)
const char * xstrerr(int error)