diff options
Diffstat (limited to 'libunbound')
| -rw-r--r-- | libunbound/context.h | 2 | ||||
| -rw-r--r-- | libunbound/libunbound.c | 17 | ||||
| -rw-r--r-- | libunbound/libworker.c | 17 | ||||
| -rw-r--r-- | libunbound/remote.h | 65 | ||||
| -rw-r--r-- | libunbound/worker.h | 19 |
5 files changed, 103 insertions, 17 deletions
diff --git a/libunbound/context.h b/libunbound/context.h index c0fc80e57be4..090df345b0e7 100644 --- a/libunbound/context.h +++ b/libunbound/context.h @@ -167,6 +167,8 @@ struct ctx_query { ub_event_callback_type cb_event; /** for async query, the callback user arg */ void* cb_arg; + /** for async query the unique info */ + void* unique_info; /** answer message, result from resolver lookup. */ uint8_t* msg; diff --git a/libunbound/libunbound.c b/libunbound/libunbound.c index 9c6a3e309717..140a4523395d 100644 --- a/libunbound/libunbound.c +++ b/libunbound/libunbound.c @@ -571,6 +571,8 @@ ub_ctx_async(struct ub_ctx* ctx, int dothread) int ub_poll(struct ub_ctx* ctx) { + if(!ctx || ctx->event_base) + return UB_INITFAIL; /* no need to hold lock while testing for readability. */ return tube_poll(ctx->rr_pipe); } @@ -578,6 +580,8 @@ ub_poll(struct ub_ctx* ctx) int ub_fd(struct ub_ctx* ctx) { + if(!ctx || ctx->event_base) + return -1; return tube_read_fd(ctx->rr_pipe); } @@ -672,6 +676,8 @@ ub_process(struct ub_ctx* ctx) int r; uint8_t* msg; uint32_t len; + if(!ctx || ctx->event_base) + return UB_INITFAIL; while(1) { msg = NULL; lock_basic_lock(&ctx->rrpipe_lock); @@ -700,6 +706,8 @@ ub_wait(struct ub_ctx* ctx) int r; uint8_t* msg; uint32_t len; + if(!ctx || ctx->event_base) + return UB_INITFAIL; /* this is basically the same loop as _process(), but with changes. * holds the rrpipe lock and waits with tube_wait */ while(1) { @@ -837,6 +845,8 @@ ub_resolve_async(struct ub_ctx* ctx, const char* name, int rrtype, struct ctx_query* q; uint8_t* msg = NULL; uint32_t len = 0; + if(!ctx || ctx->event_base) + return UB_INITFAIL; if(async_id) *async_id = 0; @@ -1467,8 +1477,15 @@ ub_ctx_set_event(struct ub_ctx* ctx, struct event_base* base) { lock_basic_lock(&ctx->cfglock); /* destroy the current worker - safe to pass in NULL */ + + /* Unlock the cfglock during libworker_delete_event, since it + * calls context_release_alloc, that wants to lock cfglock again. + * Since the event base is used from one thread, the one that + * called this function, it is safe to do so. */ + lock_basic_unlock(&ctx->cfglock); libworker_delete_event(ctx->event_worker); ctx->event_worker = NULL; + lock_basic_lock(&ctx->cfglock); new_base = ub_libevent_event_base(base); if (new_base) ctx->event_base = new_base; diff --git a/libunbound/libworker.c b/libunbound/libworker.c index d70527f59f66..2d6029f0c7ed 100644 --- a/libunbound/libworker.c +++ b/libunbound/libworker.c @@ -651,7 +651,8 @@ int libworker_fg(struct ub_ctx* ctx, struct ctx_query* q) } /* process new query */ if(!mesh_new_callback(w->env->mesh, &qinfo, qflags, &edns, - w->back->udp_buff, qid, libworker_fg_done_cb, q, 0)) { + w->back->udp_buff, qid, libworker_fg_done_cb, q, 0, + &q->unique_info)) { free(qinfo.qname); return UB_NOMEM; } @@ -732,7 +733,8 @@ int libworker_attach_mesh(struct ub_ctx* ctx, struct ctx_query* q, if(async_id) *async_id = q->querynum; if(!mesh_new_callback(w->env->mesh, &qinfo, qflags, &edns, - w->back->udp_buff, qid, libworker_event_done_cb, q, 0)) { + w->back->udp_buff, qid, libworker_event_done_cb, q, 0, + &q->unique_info)) { free(qinfo.qname); return UB_NOMEM; } @@ -870,7 +872,8 @@ handle_newq(struct libworker* w, uint8_t* buf, uint32_t len) q->w = w; /* process new query */ if(!mesh_new_callback(w->env->mesh, &qinfo, qflags, &edns, - w->back->udp_buff, qid, libworker_bg_done_cb, q, 0)) { + w->back->udp_buff, qid, libworker_bg_done_cb, q, 0, + &q->unique_info)) { add_bg_result(w, q, NULL, UB_NOMEM, NULL, 0); } free(qinfo.qname); @@ -888,7 +891,8 @@ struct outbound_entry* libworker_send_query(struct query_info* qinfo, int check_ratelimit, struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone, size_t zonelen, int tcp_upstream, int ssl_upstream, char* tls_auth_name, - struct module_qstate* q, int* was_ratelimited) + struct module_qstate* q, int* was_ratelimited, + int* ratelimit_incremented) { struct libworker* w = (struct libworker*)q->env->worker; struct outbound_entry* e = (struct outbound_entry*)regional_alloc( @@ -900,7 +904,7 @@ struct outbound_entry* libworker_send_query(struct query_info* qinfo, want_dnssec, nocaps, check_ratelimit, tcp_upstream, ssl_upstream, tls_auth_name, addr, addrlen, zone, zonelen, q, libworker_handle_service_reply, e, w->back->udp_buff, q->env, - was_ratelimited); + was_ratelimited, ratelimit_incremented); if(!e->qsent) { return NULL; } @@ -985,7 +989,8 @@ struct outbound_entry* worker_send_query(struct query_info* ATTR_UNUSED(qinfo), struct sockaddr_storage* ATTR_UNUSED(addr), socklen_t ATTR_UNUSED(addrlen), uint8_t* ATTR_UNUSED(zone), size_t ATTR_UNUSED(zonelen), int ATTR_UNUSED(tcp_upstream), int ATTR_UNUSED(ssl_upstream), char* ATTR_UNUSED(tls_auth_name), - struct module_qstate* ATTR_UNUSED(q), int* ATTR_UNUSED(was_ratelimited)) + struct module_qstate* ATTR_UNUSED(q), int* ATTR_UNUSED(was_ratelimited), + int* ATTR_UNUSED(ratelimit_incremented)) { log_assert(0); return 0; diff --git a/libunbound/remote.h b/libunbound/remote.h new file mode 100644 index 000000000000..4730c8e49fc5 --- /dev/null +++ b/libunbound/remote.h @@ -0,0 +1,65 @@ +/* + * libunbound/remote.h - prototypes for remote control methods. + * + * Copyright (c) 2026, NLnet Labs. All rights reserved. + * + * This software is open source. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the NLNET LABS nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * + * This file declares the methods that must be implemented to use the + * remote control service. + */ + +#ifndef LIBUNBOUND_REMOTE_H +#define LIBUNBOUND_REMOTE_H + +struct comm_reply; +struct comm_point; + +/** fast reload thread commands to remote service thread event callback */ +void fast_reload_service_cb(int fd, short bits, void* arg); + +/** fast reload callback for the remote control client connection */ +int fast_reload_client_callback(struct comm_point* c, void* arg, int err, + struct comm_reply* rep); + +/** handle remote control accept callbacks */ +int remote_accept_callback(struct comm_point*, void*, int, struct comm_reply*); + +/** handle remote control data callbacks */ +int remote_control_callback(struct comm_point*, void*, int, struct comm_reply*); + +/** routine to printout option values over SSL */ +void remote_get_opt_ssl(char* line, void* arg); + +#endif /* LIBUNBOUND_REMOTE_H */ diff --git a/libunbound/worker.h b/libunbound/worker.h index 0fa5bfa99430..48f9ee15be17 100644 --- a/libunbound/worker.h +++ b/libunbound/worker.h @@ -70,6 +70,8 @@ struct query_info; * @param q: which query state to reactivate upon return. * @param was_ratelimited: it will signal back if the query failed to pass the * ratelimit check. + * @param ratelimit_incremented: set to true if the ratelimit counter + * was increased. * @return: false on failure (memory or socket related). no query was * sent. */ @@ -78,7 +80,8 @@ struct outbound_entry* libworker_send_query(struct query_info* qinfo, int check_ratelimit, struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone, size_t zonelen, int tcp_upstream, int ssl_upstream, char* tls_auth_name, - struct module_qstate* q, int* was_ratelimited); + struct module_qstate* q, int* was_ratelimited, + int* ratelimit_incremented); /** process incoming serviced query replies from the network */ int libworker_handle_service_reply(struct comm_point* c, void* arg, int error, @@ -126,6 +129,8 @@ void worker_sighandler(int sig, void* arg); * @param q: which query state to reactivate upon return. * @param was_ratelimited: it will signal back if the query failed to pass the * ratelimit check. + * @param ratelimit_incremented: set to true if the ratelimit counter + * was increased. * @return: false on failure (memory or socket related). no query was * sent. */ @@ -134,7 +139,8 @@ struct outbound_entry* worker_send_query(struct query_info* qinfo, int check_ratelimit, struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone, size_t zonelen, int tcp_upstream, int ssl_upstream, char* tls_auth_name, - struct module_qstate* q, int* was_ratelimited); + struct module_qstate* q, int* was_ratelimited, + int* ratelimit_incremented); /** * process control messages from the main thread. Frees the control @@ -171,13 +177,4 @@ void worker_start_accept(void* arg); /** stop accept callback handler */ void worker_stop_accept(void* arg); -/** handle remote control accept callbacks */ -int remote_accept_callback(struct comm_point*, void*, int, struct comm_reply*); - -/** handle remote control data callbacks */ -int remote_control_callback(struct comm_point*, void*, int, struct comm_reply*); - -/** routine to printout option values over SSL */ -void remote_get_opt_ssl(char* line, void* arg); - #endif /* LIBUNBOUND_WORKER_H */ |
