Deleted Added
full compact
ntp_intres.c (280849) ntp_intres.c (289764)
1/*
2 * ntp_intres.c - Implements a generic blocking worker child or thread,
3 * initially to provide a nonblocking solution for DNS
4 * name to address lookups available with getaddrinfo().
5 *
6 * This is a new implementation as of 2009 sharing the filename and
7 * very little else with the prior implementation, which used a
8 * temporary file to receive a single set of requests from the parent,

--- 235 unchanged lines hidden (view full) ---

244 blocking_gai_req * gai_req;
245 u_int idx;
246 dnschild_ctx * child_ctx;
247 size_t req_size;
248 size_t nodesize;
249 size_t servsize;
250 time_t now;
251
1/*
2 * ntp_intres.c - Implements a generic blocking worker child or thread,
3 * initially to provide a nonblocking solution for DNS
4 * name to address lookups available with getaddrinfo().
5 *
6 * This is a new implementation as of 2009 sharing the filename and
7 * very little else with the prior implementation, which used a
8 * temporary file to receive a single set of requests from the parent,

--- 235 unchanged lines hidden (view full) ---

244 blocking_gai_req * gai_req;
245 u_int idx;
246 dnschild_ctx * child_ctx;
247 size_t req_size;
248 size_t nodesize;
249 size_t servsize;
250 time_t now;
251
252 NTP_REQUIRE(NULL != node);
252 REQUIRE(NULL != node);
253 if (NULL != hints) {
253 if (NULL != hints) {
254 NTP_REQUIRE(0 == hints->ai_addrlen);
255 NTP_REQUIRE(NULL == hints->ai_addr);
256 NTP_REQUIRE(NULL == hints->ai_canonname);
257 NTP_REQUIRE(NULL == hints->ai_next);
254 REQUIRE(0 == hints->ai_addrlen);
255 REQUIRE(NULL == hints->ai_addr);
256 REQUIRE(NULL == hints->ai_canonname);
257 REQUIRE(NULL == hints->ai_next);
258 }
259
260 idx = get_dnschild_ctx();
261 child_ctx = dnschild_contexts[idx];
262
263 nodesize = strlen(node) + 1;
264 servsize = strlen(service) + 1;
265 req_size = sizeof(*gai_req) + nodesize + servsize;

--- 149 unchanged lines hidden (view full) ---

415
416 /* leave fixup of ai_addr pointer for receiver */
417
418 ai = ai->ai_next;
419 }
420
421 ai = ai_res;
422 while (NULL != ai) {
258 }
259
260 idx = get_dnschild_ctx();
261 child_ctx = dnschild_contexts[idx];
262
263 nodesize = strlen(node) + 1;
264 servsize = strlen(service) + 1;
265 req_size = sizeof(*gai_req) + nodesize + servsize;

--- 149 unchanged lines hidden (view full) ---

415
416 /* leave fixup of ai_addr pointer for receiver */
417
418 ai = ai->ai_next;
419 }
420
421 ai = ai_res;
422 while (NULL != ai) {
423 NTP_INSIST(ai->ai_addrlen <= sizeof(sockaddr_u));
423 INSIST(ai->ai_addrlen <= sizeof(sockaddr_u));
424 memcpy(cp, ai->ai_addr, ai->ai_addrlen);
425 cp += sizeof(sockaddr_u);
426
427 ai = ai->ai_next;
428 }
429
430 ai = ai_res;
431 while (NULL != ai) {

--- 131 unchanged lines hidden (view full) ---

563 for (i = 0; i < gai_resp->ai_count; i++) {
564 if (NULL != ai[i].ai_addr)
565 ai[i].ai_addr = &psau->sa;
566 psau++;
567 if (NULL != ai[i].ai_canonname)
568 ai[i].ai_canonname += (size_t)canon_start;
569 }
570
424 memcpy(cp, ai->ai_addr, ai->ai_addrlen);
425 cp += sizeof(sockaddr_u);
426
427 ai = ai->ai_next;
428 }
429
430 ai = ai_res;
431 while (NULL != ai) {

--- 131 unchanged lines hidden (view full) ---

563 for (i = 0; i < gai_resp->ai_count; i++) {
564 if (NULL != ai[i].ai_addr)
565 ai[i].ai_addr = &psau->sa;
566 psau++;
567 if (NULL != ai[i].ai_canonname)
568 ai[i].ai_canonname += (size_t)canon_start;
569 }
570
571 NTP_ENSURE((char *)psau == canon_start);
571 ENSURE((char *)psau == canon_start);
572
573 if (!gai_resp->ai_count)
574 ai = NULL;
575
576 (*gai_req->callback)(gai_resp->retcode, gai_resp->gai_errno,
577 gai_req->context, node, service,
578 &gai_req->hints, ai);
579

--- 49 unchanged lines hidden (view full) ---

629 void * context
630 )
631{
632 blocking_gni_req * gni_req;
633 u_int idx;
634 dnschild_ctx * child_ctx;
635 time_t time_now;
636
572
573 if (!gai_resp->ai_count)
574 ai = NULL;
575
576 (*gai_req->callback)(gai_resp->retcode, gai_resp->gai_errno,
577 gai_req->context, node, service,
578 &gai_req->hints, ai);
579

--- 49 unchanged lines hidden (view full) ---

629 void * context
630 )
631{
632 blocking_gni_req * gni_req;
633 u_int idx;
634 dnschild_ctx * child_ctx;
635 time_t time_now;
636
637 NTP_REQUIRE(hostoctets);
638 NTP_REQUIRE(hostoctets + servoctets < 1024);
637 REQUIRE(hostoctets);
638 REQUIRE(hostoctets + servoctets < 1024);
639
640 idx = get_dnschild_ctx();
641 child_ctx = dnschild_contexts[idx];
642
643 gni_req = emalloc_zero(sizeof(*gni_req));
644
645 gni_req->octets = sizeof(*gni_req);
646 gni_req->dns_idx = idx;

--- 47 unchanged lines hidden (view full) ---

694
695 octets = gni_req->hostoctets + gni_req->servoctets;
696
697 /*
698 * Some alloca() implementations are fragile regarding
699 * large allocations. We only need room for the host
700 * and service names.
701 */
639
640 idx = get_dnschild_ctx();
641 child_ctx = dnschild_contexts[idx];
642
643 gni_req = emalloc_zero(sizeof(*gni_req));
644
645 gni_req->octets = sizeof(*gni_req);
646 gni_req->dns_idx = idx;

--- 47 unchanged lines hidden (view full) ---

694
695 octets = gni_req->hostoctets + gni_req->servoctets;
696
697 /*
698 * Some alloca() implementations are fragile regarding
699 * large allocations. We only need room for the host
700 * and service names.
701 */
702 NTP_REQUIRE(octets < sizeof(host));
702 REQUIRE(octets < sizeof(host));
703 service = host + gni_req->hostoctets;
704
705 worker_ctx = get_worker_context(c, gni_req->dns_idx);
706 scheduled_sleep(gni_req->scheduled, gni_req->earliest,
707 worker_ctx);
708 reload_resolv_conf(worker_ctx);
709
710 /*

--- 59 unchanged lines hidden (view full) ---

770
771 if (0 == gni_resp->retcode) {
772 memcpy(cp, host, gni_resp->hostoctets);
773 cp += gni_resp->hostoctets;
774 memcpy(cp, service, gni_resp->servoctets);
775 cp += gni_resp->servoctets;
776 }
777
703 service = host + gni_req->hostoctets;
704
705 worker_ctx = get_worker_context(c, gni_req->dns_idx);
706 scheduled_sleep(gni_req->scheduled, gni_req->earliest,
707 worker_ctx);
708 reload_resolv_conf(worker_ctx);
709
710 /*

--- 59 unchanged lines hidden (view full) ---

770
771 if (0 == gni_resp->retcode) {
772 memcpy(cp, host, gni_resp->hostoctets);
773 cp += gni_resp->hostoctets;
774 memcpy(cp, service, gni_resp->servoctets);
775 cp += gni_resp->servoctets;
776 }
777
778 NTP_INSIST((size_t)(cp - (char *)resp) == resp_octets);
779 NTP_INSIST(resp_octets - sizeof(*resp) == gni_resp->octets);
778 INSIST((size_t)(cp - (char *)resp) == resp_octets);
779 INSIST(resp_octets - sizeof(*resp) == gni_resp->octets);
780
781 rc = queue_blocking_response(c, resp, resp_octets, req);
782 if (rc)
783 msyslog(LOG_ERR, "blocking_getnameinfo unable to queue response");
784 return rc;
785}
786
787

--- 341 unchanged lines hidden ---
780
781 rc = queue_blocking_response(c, resp, resp_octets, req);
782 if (rc)
783 msyslog(LOG_ERR, "blocking_getnameinfo unable to queue response");
784 return rc;
785}
786
787

--- 341 unchanged lines hidden ---