dns.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /* Copyright 2003 Roger Dingledine. */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. /* See http://elvin.dstc.com/ListArchive/elvin-dev/archive/2001/09/msg00027.html
  5. * for some approaches to asynchronous dns. We will want to switch once one of
  6. * them becomes more commonly available.
  7. */
  8. #include "or.h"
  9. #include "tree.h"
  10. extern or_options_t options; /* command-line and config-file options */
  11. #define MAX_ADDRESSLEN 256
  12. #define MAX_DNSWORKERS 50
  13. #define MIN_DNSWORKERS 3
  14. #define MAX_IDLE_DNSWORKERS 10
  15. #define DNS_RESOLVE_FAILED_TRANSIENT 1
  16. #define DNS_RESOLVE_FAILED_PERMANENT 2
  17. #define DNS_RESOLVE_SUCCEEDED 3
  18. int num_dnsworkers=0;
  19. int num_dnsworkers_busy=0;
  20. struct pending_connection_t {
  21. struct connection_t *conn;
  22. struct pending_connection_t *next;
  23. };
  24. struct cached_resolve {
  25. SPLAY_ENTRY(cached_resolve) node;
  26. char address[MAX_ADDRESSLEN]; /* the hostname to be resolved */
  27. uint32_t addr; /* in host order. I know I'm horrible for assuming ipv4 */
  28. char state; /* 0 is pending; 1 means answer is valid; 2 means resolve failed */
  29. #define CACHE_STATE_PENDING 0
  30. #define CACHE_STATE_VALID 1
  31. #define CACHE_STATE_FAILED 2
  32. uint32_t expire; /* remove untouched items from cache after some time? */
  33. struct pending_connection_t *pending_connections;
  34. struct cached_resolve *next;
  35. };
  36. static void purge_expired_resolves(uint32_t now);
  37. static int assign_to_dnsworker(connection_t *exitconn);
  38. static void dns_purge_resolve(struct cached_resolve *resolve);
  39. static void dns_found_answer(char *address, uint32_t addr, char outcome);
  40. int dnsworker_main(void *data);
  41. static int spawn_dnsworker(void);
  42. static void spawn_enough_dnsworkers(void);
  43. static SPLAY_HEAD(cache_tree, cached_resolve) cache_root;
  44. static int compare_cached_resolves(struct cached_resolve *a,
  45. struct cached_resolve *b) {
  46. /* make this smarter one day? */
  47. return strncasecmp(a->address, b->address, MAX_ADDRESSLEN);
  48. }
  49. SPLAY_PROTOTYPE(cache_tree, cached_resolve, node, compare_cached_resolves);
  50. SPLAY_GENERATE(cache_tree, cached_resolve, node, compare_cached_resolves);
  51. static void init_cache_tree(void) {
  52. SPLAY_INIT(&cache_root);
  53. }
  54. void dns_init(void) {
  55. init_cache_tree();
  56. spawn_enough_dnsworkers();
  57. }
  58. static struct cached_resolve *oldest_cached_resolve = NULL; /* linked list, */
  59. static struct cached_resolve *newest_cached_resolve = NULL; /* oldest to newest */
  60. static void purge_expired_resolves(uint32_t now) {
  61. struct cached_resolve *resolve;
  62. /* this is fast because the linked list
  63. * oldest_cached_resolve is ordered by when they came in.
  64. */
  65. while(oldest_cached_resolve && (oldest_cached_resolve->expire < now)) {
  66. resolve = oldest_cached_resolve;
  67. log(LOG_DEBUG,"Forgetting old cached resolve (expires %lu)", (unsigned long)resolve->expire);
  68. if(resolve->state == CACHE_STATE_PENDING) {
  69. log_fn(LOG_WARN,"Expiring a dns resolve that's still pending. Forgot to cull it?");
  70. /* XXX if resolve->pending_connections is used, then we're probably
  71. * introducing bugs by closing resolve without notifying those streams.
  72. */
  73. }
  74. oldest_cached_resolve = resolve->next;
  75. if(!oldest_cached_resolve) /* if there are no more, */
  76. newest_cached_resolve = NULL; /* then make sure the list's tail knows that too */
  77. SPLAY_REMOVE(cache_tree, &cache_root, resolve);
  78. tor_free(resolve);
  79. }
  80. }
  81. /* See if we have a cache entry for 'exitconn->address'. if so,
  82. * if resolve valid, put it into exitconn->addr and return 1.
  83. * If resolve failed, return -1.
  84. *
  85. * Else, if seen before and pending, add conn to the pending list,
  86. * and return 0.
  87. *
  88. * Else, if not seen before, add conn to pending list, hand to
  89. * dns farm, and return 0.
  90. */
  91. int dns_resolve(connection_t *exitconn) {
  92. struct cached_resolve *resolve;
  93. struct cached_resolve search;
  94. struct pending_connection_t *pending_connection;
  95. struct in_addr in;
  96. uint32_t now = time(NULL);
  97. assert_connection_ok(exitconn, 0);
  98. /* first check if exitconn->address is an IP. If so, we already
  99. * know the answer. */
  100. if (tor_inet_aton(exitconn->address, &in) != 0) {
  101. exitconn->addr = ntohl(in.s_addr);
  102. return 1;
  103. }
  104. /* then take this opportunity to see if there are any expired
  105. * resolves in the tree. */
  106. purge_expired_resolves(now);
  107. /* now check the tree to see if 'address' is already there. */
  108. strncpy(search.address, exitconn->address, MAX_ADDRESSLEN);
  109. search.address[MAX_ADDRESSLEN-1] = 0;
  110. resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
  111. if(resolve) { /* already there */
  112. switch(resolve->state) {
  113. case CACHE_STATE_PENDING:
  114. /* add us to the pending list */
  115. pending_connection = tor_malloc(sizeof(struct pending_connection_t));
  116. pending_connection->conn = exitconn;
  117. pending_connection->next = resolve->pending_connections;
  118. resolve->pending_connections = pending_connection;
  119. log_fn(LOG_DEBUG,"Connection (fd %d) waiting for pending DNS resolve of '%s'",
  120. exitconn->s, exitconn->address);
  121. exitconn->state = EXIT_CONN_STATE_RESOLVING;
  122. return 0;
  123. case CACHE_STATE_VALID:
  124. exitconn->addr = resolve->addr;
  125. log_fn(LOG_DEBUG,"Connection (fd %d) found cached answer for '%s'",
  126. exitconn->s, exitconn->address);
  127. return 1;
  128. case CACHE_STATE_FAILED:
  129. return -1;
  130. }
  131. assert(0);
  132. }
  133. /* not there, need to add it */
  134. resolve = tor_malloc_zero(sizeof(struct cached_resolve));
  135. resolve->state = CACHE_STATE_PENDING;
  136. resolve->expire = now + MAX_DNS_ENTRY_AGE;
  137. strncpy(resolve->address, exitconn->address, MAX_ADDRESSLEN);
  138. resolve->address[MAX_ADDRESSLEN-1] = 0;
  139. /* add us to the pending list */
  140. pending_connection = tor_malloc(sizeof(struct pending_connection_t));
  141. pending_connection->conn = exitconn;
  142. pending_connection->next = NULL;
  143. resolve->pending_connections = pending_connection;
  144. exitconn->state = EXIT_CONN_STATE_RESOLVING;
  145. /* add us to the linked list of resolves */
  146. if (!oldest_cached_resolve) {
  147. oldest_cached_resolve = resolve;
  148. } else {
  149. newest_cached_resolve->next = resolve;
  150. }
  151. newest_cached_resolve = resolve;
  152. SPLAY_INSERT(cache_tree, &cache_root, resolve);
  153. return assign_to_dnsworker(exitconn);
  154. }
  155. static int assign_to_dnsworker(connection_t *exitconn) {
  156. connection_t *dnsconn;
  157. unsigned char len;
  158. assert(exitconn->state == EXIT_CONN_STATE_RESOLVING);
  159. spawn_enough_dnsworkers(); /* respawn here, to be sure there are enough */
  160. dnsconn = connection_get_by_type_state(CONN_TYPE_DNSWORKER, DNSWORKER_STATE_IDLE);
  161. if(!dnsconn) {
  162. log_fn(LOG_WARN,"no idle dns workers. Failing.");
  163. dns_cancel_pending_resolve(exitconn->address);
  164. return -1;
  165. }
  166. log_fn(LOG_DEBUG, "Connection (fd %d) needs to resolve '%s'; assigning to DNSWorker (fd %d)",
  167. exitconn->s, exitconn->address, dnsconn->s);
  168. tor_free(dnsconn->address);
  169. dnsconn->address = tor_strdup(exitconn->address);
  170. dnsconn->state = DNSWORKER_STATE_BUSY;
  171. num_dnsworkers_busy++;
  172. len = strlen(dnsconn->address);
  173. connection_write_to_buf(&len, 1, dnsconn);
  174. connection_write_to_buf(dnsconn->address, len, dnsconn);
  175. // log_fn(LOG_DEBUG,"submitted '%s'", exitconn->address);
  176. return 0;
  177. }
  178. void connection_dns_remove(connection_t *conn)
  179. {
  180. struct pending_connection_t *pend, *victim;
  181. struct cached_resolve search;
  182. struct cached_resolve *resolve;
  183. strncpy(search.address, conn->address, MAX_ADDRESSLEN);
  184. search.address[MAX_ADDRESSLEN-1] = 0;
  185. resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
  186. if(!resolve) {
  187. log_fn(LOG_WARN,"Address '%s' is not pending. Dropping.", conn->address);
  188. return;
  189. }
  190. assert(resolve->pending_connections);
  191. assert_connection_ok(conn,0);
  192. pend = resolve->pending_connections;
  193. if(pend->conn == conn) {
  194. resolve->pending_connections = pend->next;
  195. tor_free(pend);
  196. log_fn(LOG_DEBUG, "First connection (fd %d) no longer waiting for resolve of '%s'",
  197. conn->s, conn->address);
  198. return;
  199. } else {
  200. for( ; pend->next; pend = pend->next) {
  201. if(pend->next->conn == conn) {
  202. victim = pend->next;
  203. pend->next = victim->next;
  204. tor_free(victim);
  205. log_fn(LOG_DEBUG, "Connection (fd %d) no longer waiting for resolve of '%s'",
  206. conn->s, conn->address);
  207. return; /* more are pending */
  208. }
  209. }
  210. assert(0); /* not reachable unless onlyconn not in pending list */
  211. }
  212. }
  213. void assert_connection_edge_not_dns_pending(connection_t *conn) {
  214. struct pending_connection_t *pend;
  215. struct cached_resolve *resolve;
  216. SPLAY_FOREACH(resolve, cache_tree, &cache_root) {
  217. for(pend = resolve->pending_connections;
  218. pend;
  219. pend = pend->next) {
  220. assert(pend->conn != conn);
  221. }
  222. }
  223. }
  224. void assert_all_pending_dns_resolves_ok(void) {
  225. struct pending_connection_t *pend;
  226. struct cached_resolve *resolve;
  227. SPLAY_FOREACH(resolve, cache_tree, &cache_root) {
  228. for(pend = resolve->pending_connections;
  229. pend;
  230. pend = pend->next) {
  231. assert_connection_ok(pend->conn, 0);
  232. }
  233. }
  234. }
  235. /* Cancel all pending connections. Then cancel the resolve itself,
  236. * and remove the 'struct cached_resolve' from the cache.
  237. */
  238. void dns_cancel_pending_resolve(char *address) {
  239. struct pending_connection_t *pend;
  240. struct cached_resolve search;
  241. struct cached_resolve *resolve;
  242. connection_t *pendconn;
  243. strncpy(search.address, address, MAX_ADDRESSLEN);
  244. search.address[MAX_ADDRESSLEN-1] = 0;
  245. resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
  246. if(!resolve) {
  247. log_fn(LOG_WARN,"Address '%s' is not pending. Dropping.", address);
  248. return;
  249. }
  250. assert(resolve->pending_connections);
  251. /* mark all pending connections to fail */
  252. log_fn(LOG_DEBUG, "Failing all connections waiting on DNS resolve of '%s'",
  253. address);
  254. while(resolve->pending_connections) {
  255. pend = resolve->pending_connections;
  256. /* So that mark_for_close doesn't double-remove the connection. */
  257. pend->conn->state = EXIT_CONN_STATE_RESOLVEFAILED;
  258. pendconn = pend->conn; /* don't pass complex things to the
  259. connection_mark_for_close macro */
  260. connection_mark_for_close(pendconn, END_STREAM_REASON_MISC);
  261. resolve->pending_connections = pend->next;
  262. tor_free(pend);
  263. }
  264. dns_purge_resolve(resolve);
  265. }
  266. static void dns_purge_resolve(struct cached_resolve *resolve) {
  267. struct cached_resolve *tmp;
  268. /* remove resolve from the linked list */
  269. if(resolve == oldest_cached_resolve) {
  270. oldest_cached_resolve = resolve->next;
  271. if(oldest_cached_resolve == NULL)
  272. newest_cached_resolve = NULL;
  273. } else {
  274. /* FFFF make it a doubly linked list if this becomes too slow */
  275. for(tmp=oldest_cached_resolve; tmp && tmp->next != resolve; tmp=tmp->next) ;
  276. assert(tmp); /* it's got to be in the list, or we screwed up somewhere else */
  277. tmp->next = resolve->next; /* unlink it */
  278. if(newest_cached_resolve == resolve)
  279. newest_cached_resolve = tmp;
  280. }
  281. /* remove resolve from the tree */
  282. SPLAY_REMOVE(cache_tree, &cache_root, resolve);
  283. tor_free(resolve);
  284. }
  285. static void dns_found_answer(char *address, uint32_t addr, char outcome) {
  286. struct pending_connection_t *pend;
  287. struct cached_resolve search;
  288. struct cached_resolve *resolve;
  289. connection_t *pendconn;
  290. strncpy(search.address, address, MAX_ADDRESSLEN);
  291. search.address[MAX_ADDRESSLEN-1] = 0;
  292. resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
  293. if(!resolve) {
  294. log_fn(LOG_INFO,"Resolved unasked address '%s'? Dropping.", address);
  295. /* XXX Why drop? Just because we don't care now doesn't mean we shouldn't
  296. * XXX cache the result for later. */
  297. return;
  298. }
  299. if (resolve->state != CACHE_STATE_PENDING) {
  300. log_fn(LOG_WARN, "Resolved '%s' which was already resolved; ignoring",
  301. address);
  302. assert(resolve->pending_connections == NULL);
  303. return;
  304. }
  305. /* Removed this assertion: in fact, we'll sometimes get a double answer
  306. * to the same question. This can happen when we ask one worker to resolve
  307. * X.Y.Z., then we cancel the request, and then we ask another worker to
  308. * resolve X.Y.Z. */
  309. /* assert(resolve->state == CACHE_STATE_PENDING); */
  310. resolve->addr = ntohl(addr);
  311. if(outcome == DNS_RESOLVE_SUCCEEDED)
  312. resolve->state = CACHE_STATE_VALID;
  313. else
  314. resolve->state = CACHE_STATE_FAILED;
  315. while(resolve->pending_connections) {
  316. pend = resolve->pending_connections;
  317. assert_connection_ok(pend->conn,time(NULL));
  318. pend->conn->addr = resolve->addr;
  319. if(resolve->state == CACHE_STATE_FAILED) {
  320. pendconn = pend->conn; /* don't pass complex things to the
  321. connection_mark_for_close macro */
  322. /* prevent double-remove. */
  323. pend->conn->state = EXIT_CONN_STATE_RESOLVEFAILED;
  324. connection_mark_for_close(pendconn, END_STREAM_REASON_RESOLVEFAILED);
  325. } else {
  326. /* prevent double-remove. */
  327. pend->conn->state = EXIT_CONN_STATE_CONNECTING;
  328. connection_exit_connect(pend->conn);
  329. }
  330. resolve->pending_connections = pend->next;
  331. tor_free(pend);
  332. }
  333. if(outcome == DNS_RESOLVE_FAILED_TRANSIENT) { /* remove from cache */
  334. dns_purge_resolve(resolve);
  335. }
  336. }
  337. /******************************************************************/
  338. int connection_dns_finished_flushing(connection_t *conn) {
  339. assert(conn && conn->type == CONN_TYPE_DNSWORKER);
  340. connection_stop_writing(conn);
  341. return 0;
  342. }
  343. int connection_dns_process_inbuf(connection_t *conn) {
  344. char success;
  345. uint32_t addr;
  346. assert(conn && conn->type == CONN_TYPE_DNSWORKER);
  347. if(conn->inbuf_reached_eof) {
  348. log_fn(LOG_WARN,"Read eof. Worker died unexpectedly.");
  349. if(conn->state == DNSWORKER_STATE_BUSY) {
  350. dns_cancel_pending_resolve(conn->address);
  351. num_dnsworkers_busy--;
  352. }
  353. num_dnsworkers--;
  354. connection_mark_for_close(conn,0);
  355. return 0;
  356. }
  357. assert(conn->state == DNSWORKER_STATE_BUSY);
  358. if(buf_datalen(conn->inbuf) < 5) /* entire answer available? */
  359. return 0; /* not yet */
  360. assert(buf_datalen(conn->inbuf) == 5);
  361. connection_fetch_from_buf(&success,1,conn);
  362. connection_fetch_from_buf((char *)&addr,sizeof(uint32_t),conn);
  363. log_fn(LOG_DEBUG, "DNSWorker (fd %d) returned answer for '%s'",
  364. conn->s, conn->address);
  365. assert(success >= DNS_RESOLVE_FAILED_TRANSIENT);
  366. assert(success <= DNS_RESOLVE_SUCCEEDED);
  367. dns_found_answer(conn->address, addr, success);
  368. tor_free(conn->address);
  369. conn->address = tor_strdup("<idle>");
  370. conn->state = DNSWORKER_STATE_IDLE;
  371. num_dnsworkers_busy--;
  372. return 0;
  373. }
  374. int dnsworker_main(void *data) {
  375. char address[MAX_ADDRESSLEN];
  376. unsigned char address_len;
  377. char answer[5];
  378. struct hostent *rent;
  379. int *fdarray = data;
  380. int fd;
  381. close(fdarray[0]); /* this is the side of the socketpair the parent uses */
  382. fd = fdarray[1]; /* this side is ours */
  383. #ifndef MS_WINDOWS
  384. connection_free_all(); /* so the child doesn't hold the parent's fd's open */
  385. #endif
  386. for(;;) {
  387. if(recv(fd, &address_len, 1, 0) != 1) {
  388. log_fn(LOG_INFO,"dnsworker exiting because tor process died.");
  389. spawn_exit();
  390. }
  391. assert(address_len > 0);
  392. if(read_all(fd, address, address_len, 1) != address_len) {
  393. log_fn(LOG_ERR,"read hostname failed. Child exiting.");
  394. spawn_exit();
  395. }
  396. address[address_len] = 0; /* null terminate it */
  397. rent = gethostbyname(address);
  398. if (!rent) {
  399. if(h_errno == TRY_AGAIN) { /* transient error -- don't cache it */
  400. log_fn(LOG_INFO,"Could not resolve dest addr %s (transient).",address);
  401. answer[0] = DNS_RESOLVE_FAILED_TRANSIENT;
  402. } else { /* permanent error, can be cached */
  403. log_fn(LOG_INFO,"Could not resolve dest addr %s (permanent).",address);
  404. answer[0] = DNS_RESOLVE_FAILED_PERMANENT;
  405. }
  406. memset(answer+1,0,4);
  407. } else {
  408. assert(rent->h_length == 4); /* break to remind us if we move away from ipv4 */
  409. answer[0] = DNS_RESOLVE_SUCCEEDED;
  410. memcpy(answer+1, rent->h_addr, 4);
  411. log_fn(LOG_INFO,"Resolved address '%s'.",address);
  412. }
  413. if(write_all(fd, answer, 5, 1) != 5) {
  414. log_fn(LOG_ERR,"writing answer failed. Child exiting.");
  415. spawn_exit();
  416. }
  417. }
  418. return 0; /* windows wants this function to return an int */
  419. }
  420. static int spawn_dnsworker(void) {
  421. int fd[2];
  422. connection_t *conn;
  423. if(tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
  424. log(LOG_ERR, "Couldn't construct socketpair: %s", strerror(errno));
  425. exit(1);
  426. }
  427. spawn_func(dnsworker_main, (void*)fd);
  428. log_fn(LOG_DEBUG,"just spawned a worker.");
  429. close(fd[1]); /* we don't need the worker's side of the pipe */
  430. conn = connection_new(CONN_TYPE_DNSWORKER);
  431. set_socket_nonblocking(fd[0]);
  432. /* set up conn so it's got all the data we need to remember */
  433. conn->s = fd[0];
  434. conn->address = tor_strdup("<unused>");
  435. if(connection_add(conn) < 0) { /* no space, forget it */
  436. log_fn(LOG_WARN,"connection_add failed. Giving up.");
  437. connection_free(conn); /* this closes fd[0] */
  438. return -1;
  439. }
  440. conn->state = DNSWORKER_STATE_IDLE;
  441. connection_start_reading(conn);
  442. return 0; /* success */
  443. }
  444. static void spawn_enough_dnsworkers(void) {
  445. int num_dnsworkers_needed; /* aim to have 1 more than needed,
  446. * but no less than min and no more than max */
  447. connection_t *dnsconn;
  448. /* XXX This may not be the best strategy. Maybe we should queue pending
  449. * requests until the old ones finish or time out: otherwise, if
  450. * the connection requests come fast enough, we never get any DNS done. -NM
  451. * XXX But if we queue them, then the adversary can pile even more
  452. * queries onto us, blocking legitimate requests for even longer.
  453. * Maybe we should compromise and only kill if it's been at it for
  454. * more than, e.g., 2 seconds. -RD
  455. */
  456. if(num_dnsworkers_busy == MAX_DNSWORKERS) {
  457. /* We always want at least one worker idle.
  458. * So find the oldest busy worker and kill it.
  459. */
  460. dnsconn = connection_get_by_type_state_lastwritten(CONN_TYPE_DNSWORKER,
  461. DNSWORKER_STATE_BUSY);
  462. assert(dnsconn);
  463. log_fn(LOG_WARN, "%d DNS workers are spawned; all are busy. Killing one.",
  464. MAX_DNSWORKERS);
  465. connection_mark_for_close(dnsconn,0);
  466. num_dnsworkers_busy--;
  467. num_dnsworkers--;
  468. }
  469. if(num_dnsworkers_busy >= MIN_DNSWORKERS)
  470. num_dnsworkers_needed = num_dnsworkers_busy+1;
  471. else
  472. num_dnsworkers_needed = MIN_DNSWORKERS;
  473. while(num_dnsworkers < num_dnsworkers_needed) {
  474. if(spawn_dnsworker() < 0) {
  475. log(LOG_WARN,"spawn_enough_dnsworkers(): spawn failed!");
  476. return;
  477. }
  478. num_dnsworkers++;
  479. }
  480. while(num_dnsworkers > num_dnsworkers_busy+MAX_IDLE_DNSWORKERS) { /* too many idle? */
  481. /* cull excess workers */
  482. log_fn(LOG_WARN,"%d of %d dnsworkers are idle. Killing one.",
  483. num_dnsworkers-num_dnsworkers_needed, num_dnsworkers);
  484. dnsconn = connection_get_by_type_state(CONN_TYPE_DNSWORKER, DNSWORKER_STATE_IDLE);
  485. assert(dnsconn);
  486. connection_mark_for_close(dnsconn,0);
  487. num_dnsworkers--;
  488. }
  489. }
  490. /*
  491. Local Variables:
  492. mode:c
  493. indent-tabs-mode:nil
  494. c-basic-offset:2
  495. End:
  496. */