worker.c (249141) | worker.c (255579) |
---|---|
1/* 2 * daemon/worker.c - worker that handles a pending list of requests. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 56 unchanged lines hidden (view full) --- 65#include "util/data/msgencode.h" 66#include "util/data/dname.h" 67#include "util/fptr_wlist.h" 68#include "util/tube.h" 69#include "iterator/iter_fwd.h" 70#include "iterator/iter_hints.h" 71#include "validator/autotrust.h" 72#include "validator/val_anchor.h" | 1/* 2 * daemon/worker.c - worker that handles a pending list of requests. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 56 unchanged lines hidden (view full) --- 65#include "util/data/msgencode.h" 66#include "util/data/dname.h" 67#include "util/fptr_wlist.h" 68#include "util/tube.h" 69#include "iterator/iter_fwd.h" 70#include "iterator/iter_hints.h" 71#include "validator/autotrust.h" 72#include "validator/val_anchor.h" |
73#include "libunbound/context.h" 74#include "libunbound/libworker.h" |
|
73 74#ifdef HAVE_SYS_TYPES_H 75# include <sys/types.h> 76#endif 77#ifdef HAVE_NETDB_H 78#include <netdb.h> 79#endif 80#include <signal.h> --- 733 unchanged lines hidden (view full) --- 814 if(edns.edns_present && edns.edns_version != 0) { 815 edns.ext_rcode = (uint8_t)(EDNS_RCODE_BADVERS>>4); 816 edns.edns_version = EDNS_ADVERTISED_VERSION; 817 edns.udp_size = EDNS_ADVERTISED_SIZE; 818 edns.bits &= EDNS_DO; 819 verbose(VERB_ALGO, "query with bad edns version."); 820 log_addr(VERB_CLIENT,"from",&repinfo->addr, repinfo->addrlen); 821 error_encode(c->buffer, EDNS_RCODE_BADVERS&0xf, &qinfo, | 75 76#ifdef HAVE_SYS_TYPES_H 77# include <sys/types.h> 78#endif 79#ifdef HAVE_NETDB_H 80#include <netdb.h> 81#endif 82#include <signal.h> --- 733 unchanged lines hidden (view full) --- 816 if(edns.edns_present && edns.edns_version != 0) { 817 edns.ext_rcode = (uint8_t)(EDNS_RCODE_BADVERS>>4); 818 edns.edns_version = EDNS_ADVERTISED_VERSION; 819 edns.udp_size = EDNS_ADVERTISED_SIZE; 820 edns.bits &= EDNS_DO; 821 verbose(VERB_ALGO, "query with bad edns version."); 822 log_addr(VERB_CLIENT,"from",&repinfo->addr, repinfo->addrlen); 823 error_encode(c->buffer, EDNS_RCODE_BADVERS&0xf, &qinfo, |
822 *(uint16_t*)ldns_buffer_begin(c->buffer), | 824 *(uint16_t*)(void *)ldns_buffer_begin(c->buffer), |
823 ldns_buffer_read_u16_at(c->buffer, 2), NULL); 824 attach_edns_record(c->buffer, &edns); 825 return 1; 826 } 827 if(edns.edns_present && edns.udp_size < NORMAL_UDP_SIZE && 828 worker->daemon->cfg->harden_short_bufsize) { 829 verbose(VERB_QUERY, "worker request: EDNS bufsize %d ignored", 830 (int)edns.udp_size); --- 47 unchanged lines hidden (view full) --- 878 &repinfo->addr, repinfo->addrlen); 879 return 1; 880 } 881 h = query_info_hash(&qinfo); 882 if((e=slabhash_lookup(worker->env.msg_cache, h, &qinfo, 0))) { 883 /* answer from cache - we have acquired a readlock on it */ 884 if(answer_from_cache(worker, &qinfo, 885 (struct reply_info*)e->data, | 825 ldns_buffer_read_u16_at(c->buffer, 2), NULL); 826 attach_edns_record(c->buffer, &edns); 827 return 1; 828 } 829 if(edns.edns_present && edns.udp_size < NORMAL_UDP_SIZE && 830 worker->daemon->cfg->harden_short_bufsize) { 831 verbose(VERB_QUERY, "worker request: EDNS bufsize %d ignored", 832 (int)edns.udp_size); --- 47 unchanged lines hidden (view full) --- 880 &repinfo->addr, repinfo->addrlen); 881 return 1; 882 } 883 h = query_info_hash(&qinfo); 884 if((e=slabhash_lookup(worker->env.msg_cache, h, &qinfo, 0))) { 885 /* answer from cache - we have acquired a readlock on it */ 886 if(answer_from_cache(worker, &qinfo, 887 (struct reply_info*)e->data, |
886 *(uint16_t*)ldns_buffer_begin(c->buffer), | 888 *(uint16_t*)(void *)ldns_buffer_begin(c->buffer), |
887 ldns_buffer_read_u16_at(c->buffer, 2), repinfo, 888 &edns)) { 889 /* prefetch it if the prefetch TTL expired */ 890 if(worker->env.cfg->prefetch && *worker->env.now >= 891 ((struct reply_info*)e->data)->prefetch_ttl) { 892 uint32_t leeway = ((struct reply_info*)e-> 893 data)->ttl - *worker->env.now; 894 lock_rw_unlock(&e->lock); --- 5 unchanged lines hidden (view full) --- 900 lock_rw_unlock(&e->lock); 901 return 1; 902 } 903 verbose(VERB_ALGO, "answer from the cache failed"); 904 lock_rw_unlock(&e->lock); 905 } 906 if(!LDNS_RD_WIRE(ldns_buffer_begin(c->buffer))) { 907 if(answer_norec_from_cache(worker, &qinfo, | 889 ldns_buffer_read_u16_at(c->buffer, 2), repinfo, 890 &edns)) { 891 /* prefetch it if the prefetch TTL expired */ 892 if(worker->env.cfg->prefetch && *worker->env.now >= 893 ((struct reply_info*)e->data)->prefetch_ttl) { 894 uint32_t leeway = ((struct reply_info*)e-> 895 data)->ttl - *worker->env.now; 896 lock_rw_unlock(&e->lock); --- 5 unchanged lines hidden (view full) --- 902 lock_rw_unlock(&e->lock); 903 return 1; 904 } 905 verbose(VERB_ALGO, "answer from the cache failed"); 906 lock_rw_unlock(&e->lock); 907 } 908 if(!LDNS_RD_WIRE(ldns_buffer_begin(c->buffer))) { 909 if(answer_norec_from_cache(worker, &qinfo, |
908 *(uint16_t*)ldns_buffer_begin(c->buffer), | 910 *(uint16_t*)(void *)ldns_buffer_begin(c->buffer), |
909 ldns_buffer_read_u16_at(c->buffer, 2), repinfo, 910 &edns)) { 911 return 1; 912 } 913 verbose(VERB_ALGO, "answer norec from cache -- " 914 "need to validate or not primed"); 915 } 916 ldns_buffer_rewind(c->buffer); --- 4 unchanged lines hidden (view full) --- 921 log_addr(VERB_CLIENT, "udp request from", 922 &repinfo->addr, repinfo->addrlen); 923 else log_addr(VERB_CLIENT, "tcp request from", 924 &repinfo->addr, repinfo->addrlen); 925 } 926 927 /* grab a work request structure for this new request */ 928 mesh_new_client(worker->env.mesh, &qinfo, | 911 ldns_buffer_read_u16_at(c->buffer, 2), repinfo, 912 &edns)) { 913 return 1; 914 } 915 verbose(VERB_ALGO, "answer norec from cache -- " 916 "need to validate or not primed"); 917 } 918 ldns_buffer_rewind(c->buffer); --- 4 unchanged lines hidden (view full) --- 923 log_addr(VERB_CLIENT, "udp request from", 924 &repinfo->addr, repinfo->addrlen); 925 else log_addr(VERB_CLIENT, "tcp request from", 926 &repinfo->addr, repinfo->addrlen); 927 } 928 929 /* grab a work request structure for this new request */ 930 mesh_new_client(worker->env.mesh, &qinfo, |
929 ldns_buffer_read_u16_at(c->buffer, 2), 930 &edns, repinfo, *(uint16_t*)ldns_buffer_begin(c->buffer)); | 931 ldns_buffer_read_u16_at(c->buffer, 2), &edns, repinfo, 932 *(uint16_t*)(void *)ldns_buffer_begin(c->buffer)); |
931 worker_mem_report(worker, NULL); 932 return 0; 933} 934 935void 936worker_sighandler(int sig, void* arg) 937{ 938 /* note that log, print, syscalls here give race conditions. */ --- 359 unchanged lines hidden (view full) --- 1298} 1299 1300/* --- fake callbacks for fptr_wlist to work --- */ 1301struct outbound_entry* libworker_send_query(uint8_t* ATTR_UNUSED(qname), 1302 size_t ATTR_UNUSED(qnamelen), uint16_t ATTR_UNUSED(qtype), 1303 uint16_t ATTR_UNUSED(qclass), uint16_t ATTR_UNUSED(flags), 1304 int ATTR_UNUSED(dnssec), int ATTR_UNUSED(want_dnssec), 1305 struct sockaddr_storage* ATTR_UNUSED(addr), | 933 worker_mem_report(worker, NULL); 934 return 0; 935} 936 937void 938worker_sighandler(int sig, void* arg) 939{ 940 /* note that log, print, syscalls here give race conditions. */ --- 359 unchanged lines hidden (view full) --- 1300} 1301 1302/* --- fake callbacks for fptr_wlist to work --- */ 1303struct outbound_entry* libworker_send_query(uint8_t* ATTR_UNUSED(qname), 1304 size_t ATTR_UNUSED(qnamelen), uint16_t ATTR_UNUSED(qtype), 1305 uint16_t ATTR_UNUSED(qclass), uint16_t ATTR_UNUSED(flags), 1306 int ATTR_UNUSED(dnssec), int ATTR_UNUSED(want_dnssec), 1307 struct sockaddr_storage* ATTR_UNUSED(addr), |
1306 socklen_t ATTR_UNUSED(addrlen), struct module_qstate* ATTR_UNUSED(q)) | 1308 socklen_t ATTR_UNUSED(addrlen), uint8_t* ATTR_UNUSED(zone), 1309 size_t ATTR_UNUSED(zonelen), struct module_qstate* ATTR_UNUSED(q)) |
1307{ 1308 log_assert(0); 1309 return 0; 1310} 1311 1312int libworker_handle_reply(struct comm_point* ATTR_UNUSED(c), 1313 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error), 1314 struct comm_reply* ATTR_UNUSED(reply_info)) --- 52 unchanged lines hidden --- | 1310{ 1311 log_assert(0); 1312 return 0; 1313} 1314 1315int libworker_handle_reply(struct comm_point* ATTR_UNUSED(c), 1316 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error), 1317 struct comm_reply* ATTR_UNUSED(reply_info)) --- 52 unchanged lines hidden --- |