From: Wouter Wijngaards Date: Thu, 29 Oct 2009 12:11:38 +0000 (+0000) Subject: do-udp: no fixed. X-Git-Tag: release-1.4.0rc1~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1d8013c67ada8df29728571528f91563d0a2ee38;p=thirdparty%2Funbound.git do-udp: no fixed. git-svn-id: file:///svn/unbound/trunk@1882 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/daemon/worker.c b/daemon/worker.c index 7d87595f8..262418170 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1050,7 +1050,8 @@ worker_init(struct worker* worker, struct config_file *cfg, cfg->do_tcp?cfg->outgoing_num_tcp:0, worker->daemon->env->infra_cache, worker->rndstate, cfg->use_caps_bits_for_id, worker->ports, worker->numports, - cfg->unwanted_threshold, &worker_alloc_cleanup, worker); + cfg->unwanted_threshold, &worker_alloc_cleanup, worker, + cfg->do_udp); if(!worker->back) { log_err("could not create outgoing sockets"); worker_delete(worker); diff --git a/doc/Changelog b/doc/Changelog index 43de8fb2b..91f009f39 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ 29 October 2009: Wouter - iana portlist updated. - edns-buffer-size option, default 4096. + - fixed do-udp: no. 28 October 2009: Wouter - removed abort on prealloc failure, error still printed but softfail. diff --git a/libunbound/libworker.c b/libunbound/libworker.c index 3491b79cc..f23b1af67 100644 --- a/libunbound/libworker.c +++ b/libunbound/libworker.c @@ -169,7 +169,7 @@ libworker_setup(struct ub_ctx* ctx, int is_bg) cfg->do_tcp?cfg->outgoing_num_tcp:0, w->env->infra_cache, w->env->rnd, cfg->use_caps_bits_for_id, ports, numports, cfg->unwanted_threshold, - &libworker_alloc_cleanup, w); + &libworker_alloc_cleanup, w, cfg->do_udp); if(!w->is_bg || w->is_bg_thread) { lock_basic_unlock(&ctx->cfglock); } diff --git a/services/outside_network.c b/services/outside_network.c index 634f5fa5b..3af16a641 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -470,7 +470,7 @@ outside_network_create(struct comm_base *base, size_t bufsize, int do_ip6, size_t num_tcp, struct infra_cache* infra, struct ub_randstate* rnd, int use_caps_for_id, int* availports, int numavailports, size_t unwanted_threshold, - void (*unwanted_action)(void*), void* unwanted_param) + void (*unwanted_action)(void*), void* unwanted_param, int do_udp) { struct outside_network* outnet = (struct outside_network*) calloc(1, sizeof(struct outside_network)); @@ -490,6 +490,7 @@ outside_network_create(struct comm_base *base, size_t bufsize, outnet->unwanted_action = unwanted_action; outnet->unwanted_param = unwanted_param; outnet->use_caps_for_id = use_caps_for_id; + outnet->do_udp = do_udp; if(numavailports == 0) { log_err("no outgoing ports available"); outside_network_delete(outnet); @@ -1439,6 +1440,24 @@ serviced_tcp_initiate(struct outside_network* outnet, } } +static int +serviced_tcp_send(struct serviced_query* sq, ldns_buffer* buff) +{ + int vs, rtt; + uint8_t edns_lame_known; + if(!infra_host(sq->outnet->infra, &sq->addr, sq->addrlen, + *sq->outnet->now_secs, &vs, &edns_lame_known, &rtt)) + return 0; + if(vs != -1) + sq->status = serviced_query_TCP_EDNS; + else sq->status = serviced_query_TCP; + serviced_encode(sq, buff, sq->status == serviced_query_TCP_EDNS); + sq->pending = pending_tcp_query(sq->outnet, buff, &sq->addr, + sq->addrlen, TCP_AUTH_QUERY_TIMEOUT, serviced_tcp_callback, + sq); + return sq->pending != NULL; +} + int serviced_udp_callback(struct comm_point* c, void* arg, int error, struct comm_reply* rep) @@ -1582,12 +1601,22 @@ outnet_serviced_query(struct outside_network* outnet, return NULL; } /* perform first network action */ - if(!serviced_udp_send(sq, buff)) { - (void)rbtree_delete(outnet->serviced, sq); - free(sq->qbuf); - free(sq); - free(cb); - return NULL; + if(outnet->do_udp) { + if(!serviced_udp_send(sq, buff)) { + (void)rbtree_delete(outnet->serviced, sq); + free(sq->qbuf); + free(sq); + free(cb); + return NULL; + } + } else { + if(!serviced_tcp_send(sq, buff)) { + (void)rbtree_delete(outnet->serviced, sq); + free(sq->qbuf); + free(sq); + free(cb); + return NULL; + } } } /* add callback to list of callbacks */ diff --git a/services/outside_network.h b/services/outside_network.h index 584f13a9b..342682524 100644 --- a/services/outside_network.h +++ b/services/outside_network.h @@ -92,6 +92,8 @@ struct outside_network { /** linked list of available commpoints, unused file descriptors, * for use as outgoing UDP ports. cp.fd=-1 in them. */ struct port_comm* unused_fds; + /** if udp is done */ + int do_udp; /** array of outgoing IP4 interfaces */ struct port_if* ip4_ifs; @@ -347,6 +349,7 @@ struct serviced_query { * @param unwanted_threshold: when to take defensive action. * @param unwanted_action: the action to take. * @param unwanted_param: user parameter to action. + * @param do_udp: if udp is done. * @return: the new structure (with no pending answers) or NULL on error. */ struct outside_network* outside_network_create(struct comm_base* base, @@ -354,7 +357,7 @@ struct outside_network* outside_network_create(struct comm_base* base, int do_ip4, int do_ip6, size_t num_tcp, struct infra_cache* infra, struct ub_randstate* rnd, int use_caps_for_id, int* availports, int numavailports, size_t unwanted_threshold, - void (*unwanted_action)(void*), void* unwanted_param); + void (*unwanted_action)(void*), void* unwanted_param, int do_udp); /** * Delete outside_network structure. diff --git a/testcode/fake_event.c b/testcode/fake_event.c index e13126e0a..79b98f89f 100644 --- a/testcode/fake_event.c +++ b/testcode/fake_event.c @@ -851,7 +851,8 @@ outside_network_create(struct comm_base* base, size_t bufsize, struct ub_randstate* ATTR_UNUSED(rnd), int ATTR_UNUSED(use_caps_for_id), int* ATTR_UNUSED(availports), int ATTR_UNUSED(numavailports), size_t ATTR_UNUSED(unwanted_threshold), - void (*unwanted_action)(void*), void* ATTR_UNUSED(unwanted_param)) + void (*unwanted_action)(void*), void* ATTR_UNUSED(unwanted_param), + int ATTR_UNUSED(do_udp)) { struct outside_network* outnet = calloc(1, sizeof(struct outside_network));