From: Wouter Wijngaards Date: Fri, 12 Jun 2009 07:53:36 +0000 (+0000) Subject: mesh callbacks review, call error if deleted unfulfilled, check fptr wlist. X-Git-Tag: release-1.3.1~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5ca6d8c50b4c1b0c6ce949e3f57ef51c9f952645;p=thirdparty%2Funbound.git mesh callbacks review, call error if deleted unfulfilled, check fptr wlist. git-svn-id: file:///svn/unbound/trunk@1652 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/daemon/worker.c b/daemon/worker.c index ac50a52a3..bb966a0cc 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1285,6 +1285,18 @@ void libworker_handle_control_cmd(struct tube* ATTR_UNUSED(tube), log_assert(0); } +void libworker_fg_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), + ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s)) +{ + log_assert(0); +} + +void libworker_bg_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), + ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s)) +{ + log_assert(0); +} + int context_query_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b)) { log_assert(0); diff --git a/doc/Changelog b/doc/Changelog index b805c55e0..6e5b8dd77 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,7 @@ 12 June 2009: Wouter - Fixup potential wrong NSEC picked out of the cache. + - If unfulfilled callbacks are deleted they are called with an error. + - fptr wlist checks for mesh callbacks. 11 June 2009: Wouter - Fix queries for type DS when forward or stub zones are there. diff --git a/doc/TODO b/doc/TODO index 8f622aecf..aba9d87d4 100644 --- a/doc/TODO +++ b/doc/TODO @@ -100,7 +100,6 @@ o infra and lame cache: easier size config (in Mb), show usage in graphs. - winevent - poll if too many fds - fwd above stub, make hole in fwds. config non-forwarded-domain names. - fix indent # ifs -- do not flush/delete callback queries or call error on callback at least. later - selective verbosity; ubcontrol trace example.com diff --git a/libunbound/libworker.c b/libunbound/libworker.c index c17dc56e8..9f42df2c9 100644 --- a/libunbound/libworker.c +++ b/libunbound/libworker.c @@ -458,8 +458,7 @@ libworker_fillup_fg(struct ctx_query* q, int rcode, ldns_buffer* buf, libworker_enter_result(q->res, buf, q->w->env->scratch, s); } -/** callback with fg results */ -static void +void libworker_fg_done_cb(void* arg, int rcode, ldns_buffer* buf, enum sec_status s) { struct ctx_query* q = (struct ctx_query*)arg; @@ -574,8 +573,7 @@ add_bg_result(struct libworker* w, struct ctx_query* q, ldns_buffer* pkt, } } -/** callback with bg results */ -static void +void libworker_bg_done_cb(void* arg, int rcode, ldns_buffer* buf, enum sec_status s) { struct ctx_query* q = (struct ctx_query*)arg; diff --git a/libunbound/libworker.h b/libunbound/libworker.h index 224f26775..93a6ad7f3 100644 --- a/libunbound/libworker.h +++ b/libunbound/libworker.h @@ -156,6 +156,14 @@ void libworker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len, void libworker_handle_result_write(struct tube* tube, uint8_t* msg, size_t len, int err, void* arg); +/** mesh callback with fg results */ +void libworker_fg_done_cb(void* arg, int rcode, ldns_buffer* buf, + enum sec_status s); + +/** mesh callback with bg results */ +void libworker_bg_done_cb(void* arg, int rcode, ldns_buffer* buf, + enum sec_status s); + /** * fill result from parsed message, on error fills servfail * @param res: is clear at start, filled in at end. diff --git a/services/mesh.c b/services/mesh.c index b1afec0c4..f1b372e5f 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -465,9 +465,15 @@ mesh_state_cleanup(struct mesh_state* mstate) /* drop unsent replies */ if(!mstate->replies_sent) { struct mesh_reply* rep; + struct mesh_cb* cb; for(rep=mstate->reply_list; rep; rep=rep->next) { comm_point_drop_reply(&rep->query_reply); } + for(cb=mstate->cb_list; cb; cb=cb->next) { + fptr_ok(fptr_whitelist_mesh_cb(cb->cb)); + (*cb->cb)(cb->cb_arg, LDNS_RCODE_SERVFAIL, NULL, + sec_status_unchecked); + } } /* de-init modules */ @@ -618,6 +624,7 @@ mesh_do_callback(struct mesh_state* m, int rcode, struct reply_info* rep, rcode = LDNS_RCODE_SERVFAIL; /* send the reply */ if(rcode) { + fptr_ok(fptr_whitelist_mesh_cb(r->cb)); (*r->cb)(r->cb_arg, rcode, r->buf, sec_status_unchecked); } else { size_t udp_size = r->edns.udp_size; @@ -631,11 +638,14 @@ mesh_do_callback(struct mesh_state* m, int rcode, struct reply_info* rep, m->s.env->scratch, udp_size, &r->edns, (int)(r->edns.bits & EDNS_DO), secure)) { + fptr_ok(fptr_whitelist_mesh_cb(r->cb)); (*r->cb)(r->cb_arg, LDNS_RCODE_SERVFAIL, r->buf, sec_status_unchecked); - } - else (*r->cb)(r->cb_arg, LDNS_RCODE_NOERROR, r->buf, + } else { + fptr_ok(fptr_whitelist_mesh_cb(r->cb)); + (*r->cb)(r->cb_arg, LDNS_RCODE_NOERROR, r->buf, rep->security); + } } m->s.env->mesh->num_reply_addrs--; } @@ -780,6 +790,7 @@ int mesh_state_add_cb(struct mesh_state* s, struct edns_data* edns, if(!r) return 0; r->buf = buf; + log_assert(fptr_whitelist_mesh_cb(r->cb)); /* early failure ifmissing*/ r->cb = cb; r->cb_arg = cb_arg; r->edns = *edns; diff --git a/services/mesh.h b/services/mesh.h index 52ab99982..2e2dca69f 100644 --- a/services/mesh.h +++ b/services/mesh.h @@ -226,7 +226,7 @@ struct mesh_cb { ldns_buffer* buf; /** callback routine for results. if rcode != 0 buf has message. - * called as cb(cb_arg, rcode, buf); + * called as cb(cb_arg, rcode, buf, sec_state); */ mesh_cb_func_t cb; /** user arg for callback */ diff --git a/smallapp/worker_cb.c b/smallapp/worker_cb.c index 684f3a9f3..f756f9cd4 100644 --- a/smallapp/worker_cb.c +++ b/smallapp/worker_cb.c @@ -42,6 +42,7 @@ */ #include "config.h" #include "util/log.h" +#include "services/mesh.h" struct comm_reply; struct comm_point; struct module_qstate; @@ -180,6 +181,18 @@ void libworker_handle_control_cmd(struct tube* ATTR_UNUSED(tube), log_assert(0); } +void libworker_fg_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), + ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s)) +{ + log_assert(0); +} + +void libworker_bg_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), + ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s)) +{ + log_assert(0); +} + int context_query_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b)) { log_assert(0); diff --git a/util/fptr_wlist.c b/util/fptr_wlist.c index 189809b22..f5e3efa17 100644 --- a/util/fptr_wlist.c +++ b/util/fptr_wlist.c @@ -376,3 +376,10 @@ int fptr_whitelist_tube_listen(tube_callback_t* fptr) else if(fptr == &libworker_handle_control_cmd) return 1; return 0; } + +int fptr_whitelist_mesh_cb(mesh_cb_func_t fptr) +{ + if(fptr == &libworker_fg_done_cb) return 1; + else if(fptr == &libworker_bg_done_cb) return 1; + return 0; +} diff --git a/util/fptr_wlist.h b/util/fptr_wlist.h index 28507b5a2..11a0905d0 100644 --- a/util/fptr_wlist.h +++ b/util/fptr_wlist.h @@ -58,6 +58,7 @@ #include "util/storage/lruhash.h" #include "util/module.h" #include "util/tube.h" +#include "services/mesh.h" /** * Macro to perform an assertion check for fptr wlist checks. @@ -307,6 +308,14 @@ int fptr_whitelist_alloc_cleanup(void (*fptr)(void*)); */ int fptr_whitelist_tube_listen(tube_callback_t* fptr); +/** + * Check function pointer whitelist for mesh state callback values. + * + * @param fptr: function pointer to check. + * @return false if not in whitelist. + */ +int fptr_whitelist_mesh_cb(mesh_cb_func_t fptr); + /** Due to module breakage by fptr wlist, these test app declarations * are presented here */ /**