net_db.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 38 Network Measurement Database */
10 
11 /*
12  * XXX XXX XXX
13  *
14  * This code may be slightly broken now. If you're getting consistent
15  * (sometimes working) corrupt data exchanges, please contact adrian
16  * (adrian@squid-cache.org) to sort them out.
17  */
18 
19 #include "squid.h"
20 #include "CachePeer.h"
21 #include "cbdata.h"
22 #include "event.h"
23 #include "fde.h"
24 #include "fs_io.h"
25 #include "FwdState.h"
26 #include "HttpReply.h"
27 #include "icmp/net_db.h"
28 #include "internal.h"
29 #include "ip/Address.h"
30 #include "log/File.h"
31 #include "MemObject.h"
32 #include "mgr/Registration.h"
33 #include "mime_header.h"
34 #include "neighbors.h"
35 #include "PeerSelectState.h"
36 #include "SquidConfig.h"
37 #include "SquidTime.h"
38 #include "Store.h"
39 #include "StoreClient.h"
40 #include "tools.h"
41 #include "wordlist.h"
42 
43 #if HAVE_SYS_STAT_H
44 #include <sys/stat.h>
45 #endif
46 
47 #if USE_ICMP
48 #include "icmp/IcmpSquid.h"
49 #include "ipcache.h"
50 #include "StoreClient.h"
51 
52 #define NETDB_REQBUF_SZ 4096
53 
54 typedef enum {
59 
61 {
63 
64 public:
66  p(aPeer),
67  r(theReq)
68  {
69  *buf = 0;
70  assert(r);
71  // TODO: check if we actually need to do this. should be implicit
73  }
74 
76  debugs(38, 3, e->url());
77  storeUnregister(sc, e, this);
78  e->unlock("netdbExchangeDone");
79  }
80 
82  StoreEntry *e = nullptr;
83  store_client *sc = nullptr;
85  int64_t used = 0;
88  int buf_ofs = 0;
90 };
91 
93 
94 static hash_table *addr_table = NULL;
95 static hash_table *host_table = NULL;
96 
98 static void netdbRelease(netdbEntry * n);
99 
100 static void netdbHashInsert(netdbEntry * n, Ip::Address &addr);
101 static void netdbHashDelete(const char *key);
102 static void netdbHostInsert(netdbEntry * n, const char *hostname);
103 static void netdbHostDelete(const net_db_name * x);
104 static void netdbPurgeLRU(void);
105 static netdbEntry *netdbLookupHost(const char *key);
106 static net_db_peer *netdbPeerByName(const netdbEntry * n, const char *);
107 static net_db_peer *netdbPeerAdd(netdbEntry * n, CachePeer * e);
108 static const char *netdbPeerName(const char *name);
113 
114 /* We have to keep a local list of CachePeer names. The Peers structure
115  * gets freed during a reconfigure. We want this database to
116  * remain persisitent, so _net_db_peer->peername points into this
117  * linked list */
118 static wordlist *peer_names = NULL;
119 
120 static void
122 {
124  n->key = n->network;
125  assert(hash_lookup(addr_table, n->network) == NULL);
126  hash_join(addr_table, n);
127 }
128 
129 static void
130 netdbHashDelete(const char *key)
131 {
132  hash_link *hptr = (hash_link *)hash_lookup(addr_table, key);
133 
134  if (hptr == NULL) {
135  debug_trap("netdbHashDelete: key not found");
136  return;
137  }
138 
139  hash_remove_link(addr_table, hptr);
140 }
141 
142 net_db_name::net_db_name(const char *hostname, netdbEntry *e) :
143  next(e ? e->hosts : nullptr),
144  net_db_entry(e)
145 {
146  key = xstrdup(hostname);
147  if (e) {
148  e->hosts = this;
149  ++ e->link_count;
150  }
151 }
152 
153 static void
154 netdbHostInsert(netdbEntry * n, const char *hostname)
155 {
156  net_db_name *x = new net_db_name(hostname, n);
157  assert(hash_lookup(host_table, hostname) == NULL);
158  hash_join(host_table, x);
159 }
160 
161 static void
163 {
164  assert(x != NULL);
165  assert(x->net_db_entry != NULL);
166 
167  netdbEntry *n = x->net_db_entry;
168  -- n->link_count;
169 
170  for (auto **X = &n->hosts; *X; X = &(*X)->next) {
171  if (*X == x) {
172  *X = x->next;
173  break;
174  }
175  }
176 
177  hash_remove_link(host_table, (hash_link *) x);
178  delete x;
179 }
180 
181 static netdbEntry *
182 netdbLookupHost(const char *key)
183 {
184  net_db_name *x = (net_db_name *) hash_lookup(host_table, key);
185  return x ? x->net_db_entry : NULL;
186 }
187 
188 static void
190 {
191  net_db_name *x;
192  net_db_name *next;
193 
194  for (x = n->hosts; x; x = next) {
195  next = x->next;
196  netdbHostDelete(x);
197  }
198 
199  n->hosts = NULL;
200  safe_free(n->peers);
201  n->peers = NULL;
202  n->n_peers = 0;
203  n->n_peers_alloc = 0;
204 
205  if (n->link_count == 0) {
207  delete n;
208  }
209 }
210 
211 static int
212 netdbLRU(const void *A, const void *B)
213 {
214  const netdbEntry *const *n1 = (const netdbEntry *const *)A;
215  const netdbEntry *const *n2 = (const netdbEntry *const *)B;
216 
217  if ((*n1)->last_use_time > (*n2)->last_use_time)
218  return (1);
219 
220  if ((*n1)->last_use_time < (*n2)->last_use_time)
221  return (-1);
222 
223  return (0);
224 }
225 
226 static void
228 {
229  netdbEntry *n;
230  netdbEntry **list;
231  int k = 0;
232  int list_count = 0;
233  int removed = 0;
234  list = (netdbEntry **)xcalloc(netdbEntry::UseCount(), sizeof(netdbEntry *));
235  hash_first(addr_table);
236 
237  while ((n = (netdbEntry *) hash_next(addr_table))) {
238  assert(list_count < netdbEntry::UseCount());
239  *(list + list_count) = n;
240  ++list_count;
241  }
242 
243  qsort((char *) list,
244  list_count,
245  sizeof(netdbEntry *),
246  netdbLRU);
247 
248  for (k = 0; k < list_count; ++k) {
249  if (netdbEntry::UseCount() < Config.Netdb.low)
250  break;
251 
252  netdbRelease(*(list + k));
253 
254  ++removed;
255  }
256 
257  xfree(list);
258 }
259 
260 static netdbEntry *
262 {
263  netdbEntry *n;
264  char *key = new char[MAX_IPSTRLEN];
266  n = (netdbEntry *) hash_lookup(addr_table, key);
267  delete[] key;
268  return n;
269 }
270 
271 static netdbEntry *
273 {
274  netdbEntry *n;
275 
276  if (netdbEntry::UseCount() > Config.Netdb.high)
277  netdbPurgeLRU();
278 
279  if ((n = netdbLookupAddr(addr)) == NULL) {
280  n = new netdbEntry;
281  netdbHashInsert(n, addr);
282  }
283 
284  return n;
285 }
286 
287 static void
289 {
291  char *hostname = NULL;
292  static_cast<generic_cbdata *>(data)->unwrap(&hostname);
293  netdbEntry *n;
294  netdbEntry *na;
295  net_db_name *x;
296  net_db_name **X;
297 
298  if (ia == NULL) {
299  xfree(hostname);
300  return;
301  }
302 
303  addr = ia->current();
304 
305  if ((n = netdbLookupHost(hostname)) == NULL) {
306  n = netdbAdd(addr);
307  netdbHostInsert(n, hostname);
308  } else if ((na = netdbLookupAddr(addr)) != n) {
309  /*
310  *hostname moved from 'network n' to 'network na'!
311  */
312 
313  if (na == NULL)
314  na = netdbAdd(addr);
315 
316  debugs(38, 3, "netdbSendPing: " << hostname << " moved from " << n->network << " to " << na->network);
317 
318  x = (net_db_name *) hash_lookup(host_table, hostname);
319 
320  if (x == NULL) {
321  debugs(38, DBG_IMPORTANT, "netdbSendPing: net_db_name list bug: " << hostname << " not found");
322  xfree(hostname);
323  return;
324  }
325 
326  /* remove net_db_name from 'network n' linked list */
327  for (X = &n->hosts; *X; X = &(*X)->next) {
328  if (*X == x) {
329  *X = x->next;
330  break;
331  }
332  }
333 
334  -- n->link_count;
335  /* point to 'network na' from host entry */
336  x->net_db_entry = na;
337  /* link net_db_name to 'network na' */
338  x->next = na->hosts;
339  na->hosts = x;
340  ++ na->link_count;
341  n = na;
342  }
343 
344  if (n->next_ping_time <= squid_curtime) {
345  debugs(38, 3, "netdbSendPing: pinging " << hostname);
346  icmpEngine.DomainPing(addr, hostname);
347  ++ n->pings_sent;
350  }
351 
352  xfree(hostname);
353 }
354 
357 {
358  Ip::Address out;
359 
360  out = in;
361 
362  /* in IPv6 the 'network' should be the routing section. */
363  if ( in.isIPv6() ) {
364  out.applyMask(64, AF_INET6);
365  debugs(14, 5, "networkFromInaddr : Masked IPv6 Address to " << in << "/64 routing part.");
366  return out;
367  }
368 
369 #if USE_CLASSFUL
370  struct in_addr b;
371 
372  in.getInAddr(b);
373 
374  if (IN_CLASSC(b.s_addr))
375  b.s_addr &= IN_CLASSC_NET;
376  else if (IN_CLASSB(b.s_addr))
377  b.s_addr &= IN_CLASSB_NET;
378  else if (IN_CLASSA(b.s_addr))
379  b.s_addr &= IN_CLASSA_NET;
380 
381  out = b;
382 
383 #endif
384 
385  debugs(14, 5, "networkFromInaddr : Masked IPv4 Address to " << out << "/24.");
386 
387  /* use /24 for everything under IPv4 */
388  out.applyMask(24, AF_INET);
389  debugs(14, 5, "networkFromInaddr : Masked IPv4 Address to " << in << "/24.");
390 
391  return out;
392 }
393 
394 static int
395 sortByRtt(const void *A, const void *B)
396 {
397  const netdbEntry *const *n1 = (const netdbEntry *const *)A;
398  const netdbEntry *const *n2 = (const netdbEntry *const *)B;
399 
400  if ((*n1)->rtt > (*n2)->rtt)
401  return 1;
402  else if ((*n1)->rtt < (*n2)->rtt)
403  return -1;
404  else
405  return 0;
406 }
407 
408 static net_db_peer *
409 netdbPeerByName(const netdbEntry * n, const char *peername)
410 {
411  int i;
412  net_db_peer *p = n->peers;
413 
414  for (i = 0; i < n->n_peers; ++i, ++p) {
415  if (!strcmp(p->peername, peername))
416  return p;
417  }
418 
419  return NULL;
420 }
421 
422 static net_db_peer *
424 {
425  net_db_peer *p;
426  net_db_peer *o;
427  int osize;
428  int i;
429 
430  if (n->n_peers == n->n_peers_alloc) {
431  o = n->peers;
432  osize = n->n_peers_alloc;
433 
434  if (n->n_peers_alloc == 0)
435  n->n_peers_alloc = 2;
436  else
437  n->n_peers_alloc <<= 1;
438 
439  debugs(38, 3, "netdbPeerAdd: Growing peer list for '" << n->network << "' to " << n->n_peers_alloc);
440 
441  n->peers = (net_db_peer *)xcalloc(n->n_peers_alloc, sizeof(net_db_peer));
442 
443  for (i = 0; i < osize; ++i)
444  *(n->peers + i) = *(o + i);
445 
446  if (osize) {
447  safe_free(o);
448  }
449  }
450 
451  p = n->peers + n->n_peers;
452  p->peername = netdbPeerName(e->host);
453  ++ n->n_peers;
454  return p;
455 }
456 
457 static int
458 sortPeerByRtt(const void *A, const void *B)
459 {
460  const net_db_peer *p1 = (net_db_peer *)A;
461  const net_db_peer *p2 = (net_db_peer *)B;
462 
463  if (p1->rtt > p2->rtt)
464  return 1;
465  else if (p1->rtt < p2->rtt)
466  return -1;
467  else
468  return 0;
469 }
470 
471 static void
472 netdbSaveState(void *foo)
473 {
474  if (strcmp(Config.netdbFilename, "none") == 0)
475  return;
476 
477  Logfile *lf;
478  netdbEntry *n;
479  net_db_name *x;
480 
481  struct timeval start = current_time;
482  int count = 0;
483  /*
484  * This was nicer when we were using stdio, but thanks to
485  * Solaris bugs, its a bad idea. fopen can fail if more than
486  * 256 FDs are open.
487  */
488  /*
489  * unlink() is here because there is currently no way to make
490  * logfileOpen() use O_TRUNC.
491  */
492  unlink(Config.netdbFilename);
493  lf = logfileOpen(Config.netdbFilename, 4096, 0);
494 
495  if (lf) {
496  int xerrno = errno;
497  debugs(50, DBG_IMPORTANT, MYNAME << Config.netdbFilename << ": " << xstrerr(xerrno));
498  return;
499  }
500 
501  hash_first(addr_table);
502 
503  while ((n = (netdbEntry *) hash_next(addr_table))) {
504  if (n->pings_recv == 0)
505  continue;
506 
507  logfilePrintf(lf, "%s %d %d %10.5f %10.5f %d %d",
508  n->network,
509  n->pings_sent,
510  n->pings_recv,
511  n->hops,
512  n->rtt,
513  (int) n->next_ping_time,
514  (int) n->last_use_time);
515 
516  for (x = n->hosts; x; x = x->next)
517  logfilePrintf(lf, " %s", hashKeyStr(x));
518 
519  logfilePrintf(lf, "\n");
520 
521  ++count;
522 
523 #undef RBUF_SZ
524 
525  }
526 
527  logfileClose(lf);
528  getCurrentTime();
529  debugs(38, DBG_IMPORTANT, "NETDB state saved; " <<
530  count << " entries, " <<
531  tvSubMsec(start, current_time) << " msec" );
532  eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1);
533 }
534 
535 static void
537 {
538  if (strcmp(Config.netdbFilename, "none") == 0)
539  return;
540 
541  char *s;
542  int fd;
543  int l;
544 
545  struct stat sb;
546  netdbEntry *n;
547  netdbEntry N;
548 
550  int count = 0;
551 
552  struct timeval start = current_time;
553  /*
554  * This was nicer when we were using stdio, but thanks to
555  * Solaris bugs, its a bad idea. fopen can fail if more than
556  * 256 FDs are open.
557  */
558  fd = file_open(Config.netdbFilename, O_RDONLY | O_BINARY);
559 
560  if (fd < 0)
561  return;
562 
563  if (fstat(fd, &sb) < 0) {
564  file_close(fd);
565  return;
566  }
567 
568  char *t;
569  char *buf = (char *)xcalloc(1, sb.st_size + 1);
570  t = buf;
571  l = FD_READ_METHOD(fd, buf, sb.st_size);
572  file_close(fd);
573 
574  if (l <= 0) {
575  safe_free (buf);
576  return;
577  };
578 
579  while ((s = strchr(t, '\n'))) {
580  char *q;
581  assert(s - buf < l);
582  *s = '\0';
583  N = netdbEntry();
584  q = strtok(t, w_space);
585  t = s + 1;
586 
587  if (NULL == q)
588  continue;
589 
590  if (! (addr = q) )
591  continue;
592 
593  if (netdbLookupAddr(addr) != NULL) /* no dups! */
594  continue;
595 
596  if ((q = strtok(NULL, w_space)) == NULL)
597  continue;
598 
599  N.pings_sent = atoi(q);
600 
601  if ((q = strtok(NULL, w_space)) == NULL)
602  continue;
603 
604  N.pings_recv = atoi(q);
605 
606  if (N.pings_recv == 0)
607  continue;
608 
609  /* give this measurement low weight */
610  N.pings_sent = 1;
611 
612  N.pings_recv = 1;
613 
614  if ((q = strtok(NULL, w_space)) == NULL)
615  continue;
616 
617  N.hops = atof(q);
618 
619  if ((q = strtok(NULL, w_space)) == NULL)
620  continue;
621 
622  N.rtt = atof(q);
623 
624  if ((q = strtok(NULL, w_space)) == NULL)
625  continue;
626 
627  N.next_ping_time = (time_t) atoi(q);
628 
629  if ((q = strtok(NULL, w_space)) == NULL)
630  continue;
631 
632  N.last_use_time = (time_t) atoi(q);
633 
634  n = new netdbEntry;
635 
636  memcpy(n, &N, sizeof(netdbEntry));
637 
638  netdbHashInsert(n, addr);
639 
640  while ((q = strtok(NULL, w_space)) != NULL) {
641  if (netdbLookupHost(q) != NULL) /* no dups! */
642  continue;
643 
644  netdbHostInsert(n, q);
645  }
646 
647  ++count;
648  }
649 
650  xfree(buf);
651  getCurrentTime();
652  debugs(38, DBG_IMPORTANT, "NETDB state reloaded; " <<
653  count << " entries, " <<
654  tvSubMsec(start, current_time) << " msec" );
655 }
656 
657 static const char *
658 netdbPeerName(const char *name)
659 {
660  const wordlist *w;
661 
662  for (w = peer_names; w; w = w->next) {
663  if (!strcmp(w->key, name))
664  return w->key;
665  }
666 
667  return wordlistAdd(&peer_names, name);
668 }
669 
670 static void
672 {
673  netdbEntry *n = (netdbEntry *)data;
674  safe_free(n->peers);
675  delete n;
676 }
677 
678 static void
680 {
681  net_db_name *x = (net_db_name *)data;
682  delete x;
683 }
684 
685 static void
687 {
689 
691  int rec_sz = 0;
692  int o;
693 
694  struct in_addr line_addr;
695  double rtt;
696  double hops;
697  char *p;
698  int j;
699  HttpReply const *rep;
700  size_t hdr_sz;
701  int nused = 0;
702  int size;
703  int oldbufofs = ex->buf_ofs;
704 
705  rec_sz = 0;
706  rec_sz += 1 + sizeof(struct in_addr);
707  rec_sz += 1 + sizeof(int);
708  rec_sz += 1 + sizeof(int);
709  debugs(38, 3, "netdbExchangeHandleReply: " << receivedData.length << " read bytes");
710 
711  if (!ex->p.valid()) {
712  debugs(38, 3, "netdbExchangeHandleReply: Peer became invalid");
713  delete ex;
714  return;
715  }
716 
717  debugs(38, 3, "netdbExchangeHandleReply: for '" << ex->p->host << ":" << ex->p->http_port << "'");
718 
719  if (receivedData.length == 0 && !receivedData.flags.error) {
720  debugs(38, 3, "netdbExchangeHandleReply: Done");
721  delete ex;
722  return;
723  }
724 
725  p = ex->buf;
726 
727  /* Get the size of the buffer now */
728  size = ex->buf_ofs + receivedData.length;
729  debugs(38, 3, "netdbExchangeHandleReply: " << size << " bytes buf");
730 
731  /* Check if we're still doing headers */
732 
733  if (ex->connstate == STATE_HEADER) {
734 
735  ex->buf_ofs += receivedData.length;
736 
737  /* skip reply headers */
738 
739  if ((hdr_sz = headersEnd(p, ex->buf_ofs))) {
740  debugs(38, 5, "netdbExchangeHandleReply: hdr_sz = " << hdr_sz);
741  rep = ex->e->getReply();
742  assert(rep->sline.status() != Http::scNone);
743  debugs(38, 3, "netdbExchangeHandleReply: reply status " << rep->sline.status());
744 
745  if (rep->sline.status() != Http::scOkay) {
746  delete ex;
747  return;
748  }
749 
750  assert((size_t)ex->buf_ofs >= hdr_sz);
751 
752  /*
753  * Now, point p to the part of the buffer where the data
754  * starts, and update the size accordingly
755  */
756  assert(ex->used == 0);
757  ex->used = hdr_sz;
758  size = ex->buf_ofs - hdr_sz;
759  p += hdr_sz;
760 
761  /* Finally, set the conn state mode to STATE_BODY */
762  ex->connstate = STATE_BODY;
763  } else {
764  StoreIOBuffer tempBuffer;
765  tempBuffer.offset = ex->buf_ofs;
766  tempBuffer.length = ex->buf_sz - ex->buf_ofs;
767  tempBuffer.data = ex->buf + ex->buf_ofs;
768  /* Have more headers .. */
769  storeClientCopy(ex->sc, ex->e, tempBuffer,
771  return;
772  }
773  }
774 
775  assert(ex->connstate == STATE_BODY);
776 
777  /* If we get here, we have some body to parse .. */
778  debugs(38, 5, "netdbExchangeHandleReply: start parsing loop, size = " << size);
779 
780  while (size >= rec_sz) {
781  debugs(38, 5, "netdbExchangeHandleReply: in parsing loop, size = " << size);
782  addr.setAnyAddr();
783  hops = rtt = 0.0;
784 
785  for (o = 0; o < rec_sz;) {
786  switch ((int) *(p + o)) {
787 
788  case NETDB_EX_NETWORK:
789  ++o;
790  /* FIXME INET6 : NetDB can still ony send IPv4 */
791  memcpy(&line_addr, p + o, sizeof(struct in_addr));
792  addr = line_addr;
793  o += sizeof(struct in_addr);
794  break;
795 
796  case NETDB_EX_RTT:
797  ++o;
798  memcpy(&j, p + o, sizeof(int));
799  o += sizeof(int);
800  rtt = (double) ntohl(j) / 1000.0;
801  break;
802 
803  case NETDB_EX_HOPS:
804  ++o;
805  memcpy(&j, p + o, sizeof(int));
806  o += sizeof(int);
807  hops = (double) ntohl(j) / 1000.0;
808  break;
809 
810  default:
811  debugs(38, DBG_IMPORTANT, "netdbExchangeHandleReply: corrupt data, aborting");
812  delete ex;
813  return;
814  }
815  }
816 
817  if (!addr.isAnyAddr() && rtt > 0)
818  netdbExchangeUpdatePeer(addr, ex->p.get(), rtt, hops);
819 
820  assert(o == rec_sz);
821 
822  ex->used += rec_sz;
823 
824  size -= rec_sz;
825 
826  p += rec_sz;
827 
828  ++nused;
829  }
830 
831  /*
832  * Copy anything that is left over to the beginning of the buffer,
833  * and adjust buf_ofs accordingly
834  */
835 
836  /*
837  * Evilly, size refers to the buf size left now,
838  * ex->buf_ofs is the original buffer size, so just copy that
839  * much data over
840  */
841  memmove(ex->buf, ex->buf + (ex->buf_ofs - size), size);
842 
843  ex->buf_ofs = size;
844 
845  /*
846  * And don't re-copy the remaining data ..
847  */
848  ex->used += size;
849 
850  /*
851  * Now the tricky bit - size _included_ the leftover bit from the _last_
852  * storeClientCopy. We don't want to include that, or our offset will be wrong.
853  * So, don't count the size of the leftover buffer we began with.
854  * This can _disappear_ when we're not tracking offsets ..
855  */
856  ex->used -= oldbufofs;
857 
858  debugs(38, 3, "netdbExchangeHandleReply: size left over in this buffer: " << size << " bytes");
859 
860  debugs(38, 3, "netdbExchangeHandleReply: used " << nused <<
861  " entries, (x " << rec_sz << " bytes) == " << nused * rec_sz <<
862  " bytes total");
863 
864  debugs(38, 3, "netdbExchangeHandleReply: used " << ex->used);
865 
866  if (EBIT_TEST(ex->e->flags, ENTRY_ABORTED)) {
867  debugs(38, 3, "netdbExchangeHandleReply: ENTRY_ABORTED");
868  delete ex;
869  } else if (ex->e->store_status == STORE_PENDING) {
870  StoreIOBuffer tempBuffer;
871  tempBuffer.offset = ex->used;
872  tempBuffer.length = ex->buf_sz - ex->buf_ofs;
873  tempBuffer.data = ex->buf + ex->buf_ofs;
874  debugs(38, 3, "netdbExchangeHandleReply: EOF not received");
875  storeClientCopy(ex->sc, ex->e, tempBuffer,
877  }
878 }
879 
880 #endif /* USE_ICMP */
881 
882 /* PUBLIC FUNCTIONS */
883 
884 void
886 {
887 #if USE_ICMP
888  Mgr::RegisterAction("netdb", "Network Measurement Database", netdbDump, 0, 1);
889 
890  if (addr_table)
891  return;
892 
893  int n = hashPrime(Config.Netdb.high / 4);
894 
895  addr_table = hash_create((HASHCMP *) strcmp, n, hash_string);
896 
897  n = hashPrime(3 * Config.Netdb.high / 4);
898 
899  host_table = hash_create((HASHCMP *) strcmp, n, hash_string);
900 
901  eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1);
902 
904 
905 #endif
906 }
907 
908 void
909 netdbPingSite(const char *hostname)
910 {
911 #if USE_ICMP
912  netdbEntry *n;
913 
914  if ((n = netdbLookupHost(hostname)) != NULL)
915  if (n->next_ping_time > squid_curtime)
916  return;
917 
919  new generic_cbdata(xstrdup(hostname)));
920 
921 #endif
922 }
923 
924 void
925 netdbHandlePingReply(const Ip::Address &from, int hops, int rtt)
926 {
927 #if USE_ICMP
928  netdbEntry *n;
929  int N;
930  debugs(38, 3, "netdbHandlePingReply: from " << from);
931 
932  if ((n = netdbLookupAddr(from)) == NULL)
933  return;
934 
935  N = ++n->pings_recv;
936 
937  if (N > 5)
938  N = 5;
939 
940  if (rtt < 1)
941  rtt = 1;
942 
943  n->hops = ((n->hops * (N - 1)) + hops) / N;
944 
945  n->rtt = ((n->rtt * (N - 1)) + rtt) / N;
946 
947  debugs(38, 3, "netdbHandlePingReply: " << n->network << "; rtt="<<
948  std::setw(5)<< std::setprecision(2) << n->rtt << " hops="<<
949  std::setw(4) << n->hops);
950 
951 #endif
952 }
953 
954 void
956 {
957 #if USE_ICMP
958  hashFreeItems(addr_table, netdbFreeNetdbEntry);
959  hashFreeMemory(addr_table);
960  addr_table = NULL;
961  hashFreeItems(host_table, netdbFreeNameEntry);
962  hashFreeMemory(host_table);
963  host_table = NULL;
964  wordlistDestroy(&peer_names);
965  peer_names = NULL;
966 #endif
967 }
968 
969 void
971 {
972 #if USE_ICMP
973  netdbEntry *n;
974  netdbEntry **list;
975  net_db_name *x;
976  int k;
977  int i;
978  int j;
979  net_db_peer *p;
980  storeAppendPrintf(sentry, "Network DB Statistics:\n");
981  storeAppendPrintf(sentry, "%-46.46s %9s %7s %5s %s\n", /* Max between 16 (IPv4) or 46 (IPv6) */
982  "Network",
983  "recv/sent",
984  "RTT",
985  "Hops",
986  "Hostnames");
987  list = (netdbEntry **)xcalloc(netdbEntry::UseCount(), sizeof(netdbEntry *));
988  i = 0;
989  hash_first(addr_table);
990 
991  while ((n = (netdbEntry *) hash_next(addr_table))) {
992  *(list + i) = n;
993  ++i;
994  }
995 
996  if (i != netdbEntry::UseCount())
997  debugs(38, DBG_CRITICAL, "WARNING: netdb_addrs count off, found " << i <<
998  ", expected " << netdbEntry::UseCount());
999 
1000  qsort((char *) list,
1001  i,
1002  sizeof(netdbEntry *),
1003  sortByRtt);
1004 
1005  for (k = 0; k < i; ++k) {
1006  n = *(list + k);
1007  storeAppendPrintf(sentry, "%-46.46s %4d/%4d %7.1f %5.1f", /* Max between 16 (IPv4) or 46 (IPv6) */
1008  n->network,
1009  n->pings_recv,
1010  n->pings_sent,
1011  n->rtt,
1012  n->hops);
1013 
1014  for (x = n->hosts; x; x = x->next)
1015  storeAppendPrintf(sentry, " %s", hashKeyStr(x));
1016 
1017  storeAppendPrintf(sentry, "\n");
1018 
1019  p = n->peers;
1020 
1021  for (j = 0; j < n->n_peers; ++j, ++p) {
1022  storeAppendPrintf(sentry, " %-22.22s %7.1f %5.1f\n",
1023  p->peername,
1024  p->rtt,
1025  p->hops);
1026  }
1027  }
1028 
1029  xfree(list);
1030 #else
1031 
1032  storeAppendPrintf(sentry,"NETDB support not compiled into this Squid cache.\n");
1033 #endif
1034 }
1035 
1036 int
1037 netdbHostHops(const char *host)
1038 {
1039 #if USE_ICMP
1040  netdbEntry *n = netdbLookupHost(host);
1041 
1042  if (n) {
1044  return (int) (n->hops + 0.5);
1045  }
1046 
1047 #endif
1048  return 0;
1049 }
1050 
1051 int
1052 netdbHostRtt(const char *host)
1053 {
1054 #if USE_ICMP
1055  netdbEntry *n = netdbLookupHost(host);
1056 
1057  if (n) {
1059  return (int) (n->rtt + 0.5);
1060  }
1061 
1062 #endif
1063  return 0;
1064 }
1065 
1066 void
1067 netdbHostData(const char *host, int *samp, int *rtt, int *hops)
1068 {
1069 #if USE_ICMP
1070  netdbEntry *n = netdbLookupHost(host);
1071 
1072  if (n == NULL)
1073  return;
1074 
1075  *samp = n->pings_recv;
1076 
1077  *rtt = (int) (n->rtt + 0.5);
1078 
1079  *hops = (int) (n->hops + 0.5);
1080 
1082 
1083 #endif
1084 }
1085 
1086 void
1087 netdbUpdatePeer(const AnyP::Uri &url, CachePeer *e, int irtt, int ihops)
1088 {
1089 #if USE_ICMP
1090  netdbEntry *n;
1091  double rtt = (double) irtt;
1092  double hops = (double) ihops;
1093  net_db_peer *p;
1094  debugs(38, 3, url.host() << ", " << ihops << " hops, " << irtt << " rtt");
1095  n = netdbLookupHost(url.host());
1096 
1097  if (n == NULL) {
1098  debugs(38, 3, "host " << url.host() << " not found");
1099  return;
1100  }
1101 
1102  if ((p = netdbPeerByName(n, e->host)) == NULL)
1103  p = netdbPeerAdd(n, e);
1104 
1105  p->rtt = rtt;
1106 
1107  p->hops = hops;
1108 
1109  p->expires = squid_curtime + 3600;
1110 
1111  if (n->n_peers < 2)
1112  return;
1113 
1114  qsort((char *) n->peers,
1115  n->n_peers,
1116  sizeof(net_db_peer),
1117  sortPeerByRtt);
1118 
1119 #endif
1120 }
1121 
1122 void
1123 netdbExchangeUpdatePeer(Ip::Address &addr, CachePeer * e, double rtt, double hops)
1124 {
1125 #if USE_ICMP
1126  netdbEntry *n;
1127  net_db_peer *p;
1128  debugs(38, 5, "netdbExchangeUpdatePeer: '" << addr << "', "<<
1129  std::setfill('0')<< std::setprecision(2) << hops << " hops, " <<
1130  rtt << " rtt");
1131 
1132  if ( !addr.isIPv4() ) {
1133  debugs(38, 5, "netdbExchangeUpdatePeer: Aborting peer update for '" << addr << "', NetDB cannot handle IPv6.");
1134  return;
1135  }
1136 
1137  n = netdbLookupAddr(addr);
1138 
1139  if (n == NULL)
1140  n = netdbAdd(addr);
1141 
1142  assert(NULL != n);
1143 
1144  if ((p = netdbPeerByName(n, e->host)) == NULL)
1145  p = netdbPeerAdd(n, e);
1146 
1147  p->rtt = rtt;
1148 
1149  p->hops = hops;
1150 
1151  p->expires = squid_curtime + 3600; /* XXX ? */
1152 
1153  if (n->n_peers < 2)
1154  return;
1155 
1156  qsort((char *) n->peers,
1157  n->n_peers,
1158  sizeof(net_db_peer),
1159  sortPeerByRtt);
1160 
1161 #endif
1162 }
1163 
1164 void
1166 {
1167 #if USE_ICMP
1168  netdbEntry *n = netdbLookupAddr(addr);
1169 
1170  if (n == NULL)
1171  return;
1172 
1173  debugs(38, 3, "netdbDeleteAddrNetwork: " << n->network);
1174 
1175  netdbRelease(n);
1176 #endif
1177 }
1178 
1179 void
1181 {
1182  HttpReply *reply = new HttpReply;
1183 #if USE_ICMP
1184 
1185  Ip::Address addr;
1186 
1187  netdbEntry *n;
1188  int i;
1189  int j;
1190  int rec_sz;
1191  char *buf;
1192 
1193  struct in_addr line_addr;
1194  s->buffer();
1195  reply->setHeaders(Http::scOkay, "OK", NULL, -1, squid_curtime, -2);
1196  s->replaceHttpReply(reply);
1197  rec_sz = 0;
1198  rec_sz += 1 + sizeof(struct in_addr);
1199  rec_sz += 1 + sizeof(int);
1200  rec_sz += 1 + sizeof(int);
1201  buf = (char *)memAllocate(MEM_4K_BUF);
1202  i = 0;
1203  hash_first(addr_table);
1204 
1205  while ((n = (netdbEntry *) hash_next(addr_table))) {
1206  if (0.0 == n->rtt)
1207  continue;
1208 
1209  if (n->rtt > 60000) /* RTT > 1 MIN probably bogus */
1210  continue;
1211 
1212  if (! (addr = n->network) )
1213  continue;
1214 
1215  /* FIXME INET6 : NetDB cannot yet handle IPv6 addresses. Ensure only IPv4 get sent. */
1216  if ( !addr.isIPv4() )
1217  continue;
1218 
1219  buf[i] = (char) NETDB_EX_NETWORK;
1220  ++i;
1221 
1222  addr.getInAddr(line_addr);
1223  memcpy(&buf[i], &line_addr, sizeof(struct in_addr));
1224 
1225  i += sizeof(struct in_addr);
1226 
1227  buf[i] = (char) NETDB_EX_RTT;
1228  ++i;
1229 
1230  j = htonl((int) (n->rtt * 1000));
1231 
1232  memcpy(&buf[i], &j, sizeof(int));
1233 
1234  i += sizeof(int);
1235 
1236  buf[i] = (char) NETDB_EX_HOPS;
1237  ++i;
1238 
1239  j = htonl((int) (n->hops * 1000));
1240 
1241  memcpy(&buf[i], &j, sizeof(int));
1242 
1243  i += sizeof(int);
1244 
1245  if (i + rec_sz > 4096) {
1246  s->append(buf, i);
1247  i = 0;
1248  }
1249  }
1250 
1251  if (i > 0) {
1252  s->append(buf, i);
1253  i = 0;
1254  }
1255 
1256  assert(0 == i);
1257  s->flush();
1258  memFree(buf, MEM_4K_BUF);
1259 #else
1260 
1261  reply->setHeaders(Http::scBadRequest, "Bad Request", NULL, -1, squid_curtime, -2);
1262  s->replaceHttpReply(reply);
1263  storeAppendPrintf(s, "NETDB support not compiled into this Squid cache.\n");
1264 #endif
1265 
1266  s->complete();
1267 }
1268 
1269 void
1271 {
1272 #if USE_ICMP
1273  CachePeer *p = (CachePeer *)data;
1274  static const SBuf netDB("netdb");
1275  char *uri = internalRemoteUri(p->host, p->http_port, "/squid-internal-dynamic/", netDB);
1276  debugs(38, 3, "Requesting '" << uri << "'");
1279 
1280  if (!req) {
1281  debugs(38, DBG_IMPORTANT, MYNAME << ": Bad URI " << uri);
1282  return;
1283  }
1284 
1285  netdbExchangeState *ex = new netdbExchangeState(p, req);
1286  ex->e = storeCreateEntry(uri, uri, RequestFlags(), Http::METHOD_GET);
1287  assert(NULL != ex->e);
1288 
1289  StoreIOBuffer tempBuffer;
1290  tempBuffer.length = ex->buf_sz;
1291  tempBuffer.data = ex->buf;
1292 
1293  ex->sc = storeClientListAdd(ex->e, ex);
1294 
1295  storeClientCopy(ex->sc, ex->e, tempBuffer,
1297  ex->r->flags.loopDetected = true; /* cheat! -- force direct */
1298 
1299  // XXX: send as Proxy-Authenticate instead
1300  if (p->login)
1301  ex->r->url.userInfo(SBuf(p->login));
1302 
1304 #endif
1305 }
1306 
1307 CachePeer *
1309 {
1310 #if USE_ICMP
1311  assert(ps);
1312  HttpRequest *request = ps->request;
1313 
1314  CachePeer *p = NULL;
1315  netdbEntry *n;
1316  const ipcache_addrs *ia;
1317  net_db_peer *h;
1318  int i;
1319  n = netdbLookupHost(request->url.host());
1320 
1321  if (NULL == n) {
1322  /* try IP addr */
1323  ia = ipcache_gethostbyname(request->url.host(), 0);
1324 
1325  if (NULL != ia)
1326  n = netdbLookupAddr(ia->current());
1327  }
1328 
1329  if (NULL == n)
1330  return NULL;
1331 
1332  if (0 == n->n_peers)
1333  return NULL;
1334 
1336 
1337  /*
1338  * Find the parent with the least RTT to the origin server.
1339  * Make sure we don't return a parent who is farther away than
1340  * we are. Note, the n->peers list is pre-sorted by RTT.
1341  */
1342  for (i = 0; i < n->n_peers; ++i) {
1343  h = &n->peers[i];
1344 
1345  if (n->rtt > 0)
1346  if (n->rtt < h->rtt)
1347  break;
1348 
1349  p = peerFindByName(h->peername);
1350 
1351  if (NULL == p) /* not found */
1352  continue;
1353 
1354  if (neighborType(p, request->url) != PEER_PARENT)
1355  continue;
1356 
1357  if (!peerHTTPOkay(p, ps)) /* not allowed */
1358  continue;
1359 
1360  return p;
1361  }
1362 
1363 #endif
1364  return NULL;
1365 }
1366 
void DomainPing(Ip::Address &to, const char *domain)
Definition: IcmpSquid.cc:180
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
char * login
Definition: CachePeer.h:175
HttpRequest * request
netdb_conn_state_t
Definition: net_db.cc:54
#define assert(EX)
Definition: assert.h:17
SQUIDCEXTERN void hash_first(hash_table *)
Definition: hash.cc:176
const char * wordlistAdd(wordlist **list, const char *key)
Definition: wordlist.cc:25
void storeClientCopy(store_client *sc, StoreEntry *e, StoreIOBuffer copyInto, STCB *callback, void *data)
static net_db_peer * netdbPeerByName(const netdbEntry *n, const char *)
Definition: net_db.cc:409
netdbExchangeState(CachePeer *aPeer, const HttpRequestPointer &theReq)
Definition: net_db.cc:65
SQUIDCEXTERN void hashFreeMemory(hash_table *)
Definition: hash.cc:272
void logfilePrintf(Logfile *lf, const char *fmt,...)
Definition: File.cc:112
int unlock(const char *context)
Definition: store.cc:457
CachePeer * netdbClosestParent(PeerSelector *ps)
Definition: net_db.cc:1308
bool loopDetected
Definition: RequestFlags.h:36
SQUIDCEXTERN HASHHASH hash_string
Definition: hash.h:45
void netdbFreeMemory(void)
Definition: net_db.cc:955
Definition: File.h:38
void netdbExchangeStart(void *data)
Definition: net_db.cc:1270
HttpRequestPointer r
Definition: net_db.cc:84
Definition: SBuf.h:86
static uint32 B
Definition: md4.c:43
static net_db_peer * netdbPeerAdd(netdbEntry *n, CachePeer *e)
Definition: net_db.cc:423
virtual void append(char const *, int)
Appends a c-string to existing packed data.
Definition: store.cc:823
#define xcalloc
Definition: membanger.c:57
static netdbEntry * netdbLookupHost(const char *key)
Definition: net_db.cc:182
store_client * sc
Definition: net_db.cc:83
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
int i
Definition: membanger.c:49
#define xstrdup
virtual void buffer()
Definition: store.cc:1635
#define safe_free(x)
Definition: xalloc.h:73
void wordlistDestroy(wordlist **list)
destroy a wordlist
Definition: wordlist.cc:16
void netdbUpdatePeer(const AnyP::Uri &url, CachePeer *e, int irtt, int ihops)
Definition: net_db.cc:1087
int n_peers
Definition: net_db.h:65
int file_open(const char *path, int mode)
Definition: fs_io.cc:46
double rtt
Definition: net_db.h:58
encapsulates DNS lookup results
Definition: LookupDetails.h:20
virtual void flush()
Definition: store.cc:1646
static void netdbReloadState(void)
Definition: net_db.cc:536
SQUIDCEXTERN void hash_join(hash_table *, hash_link *)
Definition: hash.cc:132
time_t next_ping_time
Definition: net_db.h:59
int netdbHostRtt(const char *host)
Definition: net_db.cc:1052
char * key
Definition: wordlist.h:33
void eventAddIsh(const char *name, EVH *func, void *arg, double delta_ish, int weight)
Definition: event.cc:116
int applyMask(const Address &mask)
Definition: Address.cc:87
store_client * storeClientListAdd(StoreEntry *e, void *data)
AnyP::ProtocolVersion http_ver
Definition: Message.h:72
#define DBG_CRITICAL
Definition: Debug.h:45
double hops
Definition: net_db.h:57
char * p
Definition: membanger.c:43
void FREE(void *)
Definition: forward.h:36
int pings_sent
Definition: net_db.h:55
const char * peername
Definition: net_db.h:40
struct timeval current_time
Definition: stub_time.cc:15
Logfile * logfileOpen(const char *path, size_t bufsz, int fatal_flag)
Definition: File.cc:38
time_t squid_curtime
Definition: stub_time.cc:17
bool isAnyAddr() const
Definition: Address.cc:163
#define w_space
void replaceHttpReply(HttpReply *, bool andStartWriting=true)
Definition: store.cc:1782
CBDATA_CLASS_INIT(netdbExchangeState)
static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *)
Same as Start() but no master xaction info (AccessLogEntry) available.
Definition: FwdState.cc:394
netdbEntry * net_db_entry
Definition: net_db.h:33
void complete()
Definition: store.cc:1058
void netdbInit(void)
Definition: net_db.cc:885
static netdbEntry * netdbLookupAddr(const Ip::Address &addr)
Definition: net_db.cc:261
bool isIPv6() const
Definition: Address.cc:157
int tvSubMsec(struct timeval, struct timeval)
Definition: stub_time.cc:20
const char * xstrerr(int error)
Definition: xstrerror.cc:83
void const char HLPCB void * data
Definition: stub_helper.cc:16
int64_t offset
Definition: StoreIOBuffer.h:55
int link_count
Definition: net_db.h:61
peer_t neighborType(const CachePeer *p, const AnyP::Uri &url)
Definition: neighbors.cc:113
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition: HttpReply.cc:161
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:776
#define DBG_IMPORTANT
Definition: Debug.h:46
void RegisterAction(char const *action, char const *desc, OBJH *handler, int pw_req_flag, int atomic)
Definition: Registration.cc:16
void * memAllocate(mem_type)
Allocate one element from the typed pool.
Definition: old_api.cc:214
HttpReply const * getReply() const
Definition: store.cc:1670
static int netdbLRU(const void *A, const void *B)
Definition: net_db.cc:212
static IPH netdbSendPing
Definition: net_db.cc:109
SQUIDCEXTERN hash_link * hash_lookup(hash_table *, const void *)
Definition: hash.cc:147
void logfileClose(Logfile *lf)
Definition: File.cc:90
int64_t used
Definition: net_db.cc:85
char network[MAX_IPSTRLEN]
Definition: net_db.h:54
Cbc * valid() const
was set and is valid
Definition: CbcPointer.h:41
static void netdbPurgeLRU(void)
Definition: net_db.cc:227
char * netdbFilename
Definition: SquidConfig.h:218
AnyP::Uri url
the request URI
Definition: HttpRequest.h:107
#define NETDB_REQBUF_SZ
Definition: net_db.cc:52
void * addr
Definition: membanger.c:46
void userInfo(const SBuf &s)
Definition: Uri.h:75
void netdbDump(StoreEntry *sentry)
Definition: net_db.cc:970
uint16_t flags
Definition: Store.h:208
SQUIDCEXTERN hash_table * hash_create(HASHCMP *, int, HASHHASH *)
Definition: hash.cc:109
SQUIDCEXTERN void hashFreeItems(hash_table *, HASHFREE *)
Definition: hash.cc:256
void ipcache_nbgethostbyname(const char *name, IPH *handler, void *handlerData)
Definition: ipcache.cc:600
static FREE netdbFreeNetdbEntry
Definition: net_db.cc:111
Http::StatusLine sline
Definition: HttpReply.h:60
net_db_name(const char *name, netdbEntry *)
Definition: net_db.cc:142
SQUIDCEXTERN const char * hashKeyStr(hash_link *)
Definition: hash.cc:317
void host(const char *src)
Definition: Uri.cc:47
bool isIPv4() const
Definition: Address.cc:151
struct StoreIOBuffer::@146 flags
static FREE netdbFreeNameEntry
Definition: net_db.cc:110
int n_peers_alloc
Definition: net_db.h:64
static int sortPeerByRtt(const void *A, const void *B)
Definition: net_db.cc:458
time_t period
Definition: SquidConfig.h:229
static void netdbHashInsert(netdbEntry *n, Ip::Address &addr)
Definition: net_db.cc:121
const char * url() const
Definition: store.cc:1600
static HttpRequest * FromUrl(const char *url, const MasterXaction::Pointer &, const HttpRequestMethod &method=Http::METHOD_GET)
Definition: HttpRequest.cc:523
void const char * buf
Definition: stub_helper.cc:16
static uint32 A
Definition: md4.c:43
net_db_name * hosts
Definition: net_db.h:62
net_db_name * next
Definition: net_db.h:32
unsigned error
Definition: StoreIOBuffer.h:52
SQUIDCEXTERN hash_link * hash_next(hash_table *)
Definition: hash.cc:192
int storeUnregister(store_client *sc, StoreEntry *e, void *data)
bool SIGHDLR int STUB void int
Definition: stub_tools.cc:68
CBDATA_CLASS(netdbExchangeState)
time_t getCurrentTime(void)
Get current time.
StoreEntry * e
Definition: net_db.cc:82
SQUIDCEXTERN int hashPrime(int n)
Definition: hash.cc:297
int netdbHostHops(const char *host)
Definition: net_db.cc:1037
RequestFlags flags
Definition: HttpRequest.h:133
store_status_t store_status
Definition: Store.h:220
static void netdbRelease(netdbEntry *n)
Definition: net_db.cc:189
#define MYNAME
Definition: Debug.h:166
const ipcache_addrs * ipcache_gethostbyname(const char *name, int flags)
Definition: ipcache.cc:720
static void netdbHostDelete(const net_db_name *x)
Definition: net_db.cc:162
net_db_peer * peers
Definition: net_db.h:63
#define FD_READ_METHOD(fd, buf, len)
Definition: fde.h:161
Definition: Uri.h:30
static void netdbSaveState(void *foo)
Definition: net_db.cc:472
static void netdbHostInsert(netdbEntry *n, const char *hostname)
Definition: net_db.cc:154
int pings_recv
Definition: net_db.h:56
void setAnyAddr()
NOTE: Does NOT clear the Port stored. Ony the Address and Type.
Definition: Address.cc:170
void memFree(void *, int type)
Free a element allocated by memAllocate()
Definition: old_api.cc:222
int peerHTTPOkay(const CachePeer *p, PeerSelector *ps)
Definition: neighbors.cc:252
void netdbExchangeUpdatePeer(Ip::Address &addr, CachePeer *e, double rtt, double hops)
Definition: net_db.cc:1123
netdb_conn_state_t connstate
Definition: net_db.cc:89
void STCB(void *, StoreIOBuffer)
Definition: StoreClient.h:16
SQUIDCEXTERN void hash_remove_link(hash_table *, hash_link *)
Definition: hash.cc:224
time_t last_use_time
Definition: net_db.h:60
void netdbHostData(const char *host, int *samp, int *rtt, int *hops)
Definition: net_db.cc:1067
int a
Definition: membanger.c:50
unsigned short http_port
Definition: CachePeer.h:78
double rtt
Definition: net_db.h:42
void IPH(const ipcache_addrs *, const Dns::LookupDetails &details, void *)
Definition: ipcache.h:219
Ip::Address networkFromInaddr(const Ip::Address &a)
Definition: net_db.cc:356
void netdbDeleteAddrNetwork(Ip::Address &addr)
Definition: net_db.cc:1165
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition: forward.h:23
static STCB netdbExchangeHandleReply
Definition: net_db.cc:112
struct SquidConfig::@111 Netdb
static const char * netdbPeerName(const char *name)
Definition: net_db.cc:658
void netdbPingSite(const char *hostname)
Definition: net_db.cc:909
char * toStr(char *buf, const unsigned int blen, int force=AF_UNSPEC) const
Definition: Address.cc:795
the ICMP RTT database (NetDB) neighbors exchange subsystem
#define O_BINARY
Definition: defines.h:204
char * internalRemoteUri(const char *host, unsigned short port, const char *dir, const SBuf &name)
Definition: internal.cc:85
IcmpSquid icmpEngine
Definition: IcmpSquid.cc:27
static void netdbHashDelete(const char *key)
Definition: net_db.cc:130
static netdbEntry * netdbAdd(Ip::Address &addr)
Definition: net_db.cc:272
double hops
Definition: net_db.h:41
bool getInAddr(struct in_addr &) const
Definition: Address.cc:1023
time_t expires
Definition: net_db.h:43
size_t headersEnd(const char *mime, size_t l, bool &containsObsFold)
Definition: mime_header.cc:16
void debug_trap(const char *message)
Definition: tools.cc:403
CbcPointer< CachePeer > p
Definition: net_db.cc:81
#define xfree
CachePeer * peerFindByName(const char *name)
Definition: neighbors.cc:1118
void file_close(int fd)
Definition: fs_io.cc:76
void netdbBinaryExchange(StoreEntry *s)
Definition: net_db.cc:1180
const Ip::Address & current() const
Definition: ipcache.h:59
static int sortByRtt(const void *A, const void *B)
Definition: net_db.cc:395
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:875
#define EBIT_TEST(flag, bit)
Definition: defines.h:107
C * getRaw() const
Definition: RefCount.h:74
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
char buf[NETDB_REQBUF_SZ]
Definition: net_db.cc:87
void netdbHandlePingReply(const Ip::Address &from, int hops, int rtt)
Definition: net_db.cc:925
Cbc * get() const
a temporary valid raw Cbc pointer or NULL
Definition: CbcPointer.h:162
int size
Definition: ModDevPoll.cc:77
char * host
Definition: CachePeer.h:41
int HASHCMP(const void *, const void *)
Definition: hash.h:13
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45
wordlist * next
Definition: wordlist.h:34

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors