Merge branch 'ondrej/remove-lib_isc_register-function' into 'main'

Remove support for external applications to register libisc

See merge request isc-projects/bind9!2420
This commit is contained in:
Ondřej Surý 2021-08-30 07:20:03 +00:00
commit 2d36920d6a
18 changed files with 73 additions and 296 deletions

View file

@ -1,3 +1,9 @@
5706. [cleanup] Remove support for external applications to register
and use libisc. Export versions of BIND 9 libraries
have not been supported for some time, but the
isc_lib_register() function was still available;
it has now been removed. [GL !2420]
5705. [bug] Change #5686 altered the internal memory structure
of zone databases, but neglected to update the
MAPAPI value for map-format zone files. This caused

View file

@ -28,7 +28,6 @@
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/hex.h>
#include <isc/lib.h>
#include <isc/log.h>
#include <isc/managers.h>
#include <isc/md.h>
@ -1737,7 +1736,6 @@ main(int argc, char *argv[]) {
argc--;
argv++;
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS) {
fatal("dns_lib_init failed: %d", result);
@ -1846,7 +1844,7 @@ cleanup:
dns_master_styledestroy(&style, mctx);
}
if (client != NULL) {
dns_client_destroy(&client);
dns_client_detach(&client);
}
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr);
if (actx != NULL) {

View file

@ -20,7 +20,6 @@
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/ht.h>
#include <isc/lib.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/netaddr.h>

View file

@ -20,7 +20,6 @@
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/ht.h>
#include <isc/lib.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/netaddr.h>

View file

@ -17,7 +17,6 @@
#include <isc/commandline.h>
#include <isc/hash.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/util.h>
@ -76,7 +75,6 @@ dyndb_init(isc_mem_t *mctx, const char *name, const char *parameters,
* to initialize libisc/libdns
*/
if (dctx->refvar != &isc_bind9) {
isc_lib_register();
isc_log_setcontext(dctx->lctx);
dns_log_setcontext(dctx->lctx);
isc_hash_set_initializer(dctx->hashinit);

View file

@ -20,7 +20,6 @@
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/ht.h>
#include <isc/lib.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/netaddr.h>

View file

@ -25,7 +25,6 @@
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/lib.h>
#include <isc/managers.h>
#include <isc/mem.h>
#include <isc/print.h>
@ -394,7 +393,6 @@ main(int argc, char *argv[]) {
altserveraddr = cp + 1;
}
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "dns_lib_init failed: %u\n", result);
@ -495,7 +493,7 @@ main(int argc, char *argv[]) {
/* Cleanup */
cleanup:
if (client != NULL) {
dns_client_destroy(&client);
dns_client_detach(&client);
}
ctxs_destroy();

View file

@ -153,6 +153,10 @@ typedef struct resarg {
static void
client_resfind(resctx_t *rctx, dns_fetchevent_t *event);
static void
cancelresolve(dns_clientrestrans_t *trans);
static void
destroyrestrans(dns_clientrestrans_t **transp);
/*
* Try honoring the operating system's preferred ephemeral port range.
@ -406,7 +410,7 @@ cleanup_lock:
static void
destroyclient(dns_client_t *client) {
dns_view_t *view;
dns_view_t *view = NULL;
isc_refcount_destroy(&client->references);
@ -433,13 +437,14 @@ destroyclient(dns_client_t *client) {
}
void
dns_client_destroy(dns_client_t **clientp) {
dns_client_t *client;
dns_client_detach(dns_client_t **clientp) {
dns_client_t *client = NULL;
REQUIRE(clientp != NULL);
REQUIRE(DNS_CLIENT_VALID(*clientp));
client = *clientp;
*clientp = NULL;
REQUIRE(DNS_CLIENT_VALID(client));
if (isc_refcount_decrement(&client->references) == 1) {
destroyclient(client);
@ -974,7 +979,8 @@ static void
resolve_done(isc_task_t *task, isc_event_t *event) {
resarg_t *resarg = event->ev_arg;
dns_clientresevent_t *rev = (dns_clientresevent_t *)event;
dns_name_t *name;
dns_name_t *name = NULL;
dns_client_t *client = resarg->client;
isc_result_t result;
UNUSED(task);
@ -988,8 +994,9 @@ resolve_done(isc_task_t *task, isc_event_t *event) {
ISC_LIST_APPEND(*resarg->namelist, name, link);
}
dns_client_destroyrestrans(&resarg->trans);
destroyrestrans(&resarg->trans);
isc_event_free(&event);
resarg->client = NULL;
if (!resarg->canceled) {
UNLOCK(&resarg->lock);
@ -1000,8 +1007,8 @@ resolve_done(isc_task_t *task, isc_event_t *event) {
* action to call isc_app_ctxsuspend when we do start
* running.
*/
result = isc_app_ctxonrun(resarg->actx, resarg->client->mctx,
task, suspend, resarg->actx);
result = isc_app_ctxonrun(resarg->actx, client->mctx, task,
suspend, resarg->actx);
if (result == ISC_R_ALREADYRUNNING) {
isc_app_ctxsuspend(resarg->actx);
}
@ -1012,8 +1019,10 @@ resolve_done(isc_task_t *task, isc_event_t *event) {
*/
UNLOCK(&resarg->lock);
isc_mutex_destroy(&resarg->lock);
isc_mem_put(resarg->client->mctx, resarg, sizeof(*resarg));
isc_mem_put(client->mctx, resarg, sizeof(*resarg));
}
dns_client_detach(&client);
}
isc_result_t
@ -1021,7 +1030,7 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name,
dns_rdataclass_t rdclass, dns_rdatatype_t type,
unsigned int options, dns_namelist_t *namelist) {
isc_result_t result;
resarg_t *resarg;
resarg_t *resarg = NULL;
REQUIRE(DNS_CLIENT_VALID(client));
REQUIRE(client->actx != NULL);
@ -1071,7 +1080,7 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name,
* tricky cleanup process.
*/
resarg->canceled = true;
dns_client_cancelresolve(resarg->trans);
cancelresolve(resarg->trans);
UNLOCK(&resarg->lock);
@ -1194,9 +1203,16 @@ cleanup:
return (result);
}
void
dns_client_cancelresolve(dns_clientrestrans_t *trans) {
resctx_t *rctx;
/*%<
* Cancel an ongoing resolution procedure started via
* dns_client_startresolve().
*
* If the resolution procedure has not completed, post its CLIENTRESDONE
* event with a result code of #ISC_R_CANCELED.
*/
static void
cancelresolve(dns_clientrestrans_t *trans) {
resctx_t *rctx = NULL;
REQUIRE(trans != NULL);
rctx = (resctx_t *)trans;
@ -1233,19 +1249,29 @@ dns_client_freeresanswer(dns_client_t *client, dns_namelist_t *namelist) {
}
}
void
dns_client_destroyrestrans(dns_clientrestrans_t **transp) {
resctx_t *rctx;
isc_mem_t *mctx;
dns_client_t *client;
/*%
* Destroy name resolution transaction state identified by '*transp'.
*
* The caller must have received the CLIENTRESDONE event (either because the
* resolution completed or because cancelresolve() was called).
*/
static void
destroyrestrans(dns_clientrestrans_t **transp) {
resctx_t *rctx = NULL;
isc_mem_t *mctx = NULL;
dns_client_t *client = NULL;
REQUIRE(transp != NULL);
rctx = (resctx_t *)*transp;
*transp = NULL;
REQUIRE(RCTX_VALID(rctx));
REQUIRE(rctx->fetch == NULL);
REQUIRE(rctx->event == NULL);
client = rctx->client;
REQUIRE(DNS_CLIENT_VALID(client));
mctx = client->mctx;
@ -1271,8 +1297,6 @@ dns_client_destroyrestrans(dns_clientrestrans_t **transp) {
rctx->magic = 0;
isc_mem_put(mctx, rctx, sizeof(*rctx));
dns_client_destroy(&client);
}
isc_result_t

View file

@ -46,15 +46,6 @@
#include <dst/dst.h>
typedef enum {
updateop_none = 0,
updateop_add = 1,
updateop_delete = 2,
updateop_exist = 3,
updateop_notexist = 4,
updateop_max = 5
} dns_client_updateop_t;
ISC_LANG_BEGINDECLS
/***
@ -75,22 +66,6 @@ ISC_LANG_BEGINDECLS
/*%< Use TCP transport. */
#define DNS_CLIENTRESOPT_TCP 0x10
/*%
* Optional flags for dns_client_(start)request.
*/
/*%< Allow running external context. */
#define DNS_CLIENTREQOPT_RESERVED 0x01
/*%< Use TCP transport. */
#define DNS_CLIENTREQOPT_TCP 0x02
/*%
* Optional flags for dns_client_(start)update.
*/
/*%< Allow running external context. */
#define DNS_CLIENTUPDOPT_RESERVED 0x01
/*%< Use TCP transport. */
#define DNS_CLIENTUPDOPT_TCP 0x02
/*%
* View name used in dns_client.
*/
@ -112,20 +87,6 @@ typedef struct dns_clientresevent {
dns_namelist_t answerlist;
} dns_clientresevent_t; /* too long? */
/*%
* A dns_clientreqevent_t is sent when a DNS request is completed by a client.
* 'result' stores the result code of the entire transaction.
* If the transaction is successfully completed but the response packet cannot
* be parsed, 'result' will store the result code of dns_message_parse().
* If the response packet is received, 'rmessage' will contain the response
* message, whether it is successfully parsed or not.
*/
typedef struct dns_clientreqevent {
ISC_EVENT_COMMON(struct dns_clientreqevent);
isc_result_t result;
dns_message_t *rmessage;
} dns_clientreqevent_t; /* too long? */
isc_result_t
dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr,
@ -166,9 +127,9 @@ dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
*/
void
dns_client_destroy(dns_client_t **clientp);
dns_client_detach(dns_client_t **clientp);
/*%<
* Destroy 'client'.
* Detach 'client' and destroy it if there are no more references.
*
* Requires:
*
@ -292,39 +253,6 @@ dns_client_startresolve(dns_client_t *client, const dns_name_t *name,
*\li Anything else Failure.
*/
void
dns_client_cancelresolve(dns_clientrestrans_t *trans);
/*%<
* Cancel an ongoing resolution procedure started via
* dns_client_startresolve().
*
* Notes:
*
*\li If the resolution procedure has not completed, post its CLIENTRESDONE
* event with a result code of #ISC_R_CANCELED.
*
* Requires:
*
*\li 'trans' is a valid transaction ID.
*/
void
dns_client_destroyrestrans(dns_clientrestrans_t **transp);
/*%<
* Destroy name resolution transaction state identified by '*transp'.
*
* Requires:
*
*\li '*transp' is a valid transaction ID.
*
*\li The caller has received the CLIENTRESDONE event (either because the
* resolution completed or because dns_client_cancelresolve() was called).
*
* Ensures:
*
*\li *transp == NULL.
*/
void
dns_client_freeresanswer(dns_client_t *client, dns_namelist_t *namelist);
/*%<
@ -362,107 +290,6 @@ dns_client_addtrustedkey(dns_client_t *client, dns_rdataclass_t rdclass,
*\li Anything else Failure.
*/
isc_result_t
dns_client_request(dns_client_t *client, dns_message_t *qmessage,
dns_message_t *rmessage, const isc_sockaddr_t *server,
unsigned int options, unsigned int parseoptions,
dns_tsec_t *tsec, unsigned int timeout,
unsigned int udptimeout, unsigned int udpretries);
isc_result_t
dns_client_startrequest(dns_client_t *client, dns_message_t *qmessage,
dns_message_t *rmessage, const isc_sockaddr_t *server,
unsigned int options, unsigned int parseoptions,
dns_tsec_t *tsec, unsigned int timeout,
unsigned int udptimeout, unsigned int udpretries,
isc_task_t *task, isc_taskaction_t action, void *arg,
dns_clientreqtrans_t **transp);
/*%<
* Send a DNS request containing a query message 'query' to 'server'.
*
* 'parseoptions' will be used when the response packet is parsed, and will be
* passed to dns_message_parse() via dns_request_getresponse(). See
* dns_message_parse() for more details.
*
* 'tsec' is a transaction security object containing, e.g. a TSIG key for
* authenticating the request/response transaction. This is optional and can
* be NULL, in which case this library performs the transaction without any
* transaction authentication.
*
* 'timeout', 'udptimeout', and 'udpretries' are passed to
* dns_request_createvia3(). See dns_request_createvia3() for more details.
*
* dns_client_request() provides a synchronous service. This function sends
* the request and blocks until a response is received. On success,
* 'rmessage' will contain the response message. The caller must provide a
* valid initialized message.
*
* It is expected that the client object passed to dns_client_request() was
* created via dns_client_create() and has external managers and contexts.
*
* dns_client_startrequest() is an asynchronous version of dns_client_request()
* and does not block. When the transaction is completed, 'action' will be
* called with the argument of a 'dns_clientreqevent_t' object, which contains
* the response message (on success). On return, '*transp' is set to an opaque
* transaction ID so that the caller can cancel this request.
*
* DNS_CLIENTREQOPT_TCP switches to the TCP (vs. UDP) transport.
*
* Requires:
*
*\li 'client' is a valid client.
*
*\li 'qmessage' and 'rmessage' are valid initialized message.
*
*\li 'server' is a valid socket address structure.
*
*\li 'task' is a valid task.
*
*\li 'transp' != NULL && *transp == NULL;
*
* Returns:
*
*\li #ISC_R_SUCCESS On success.
*
*\li Anything else Failure.
*
*\li Any result that dns_message_parse() can return.
*/
void
dns_client_cancelrequest(dns_clientreqtrans_t *transp);
/*%<
* Cancel an ongoing DNS request procedure started via
* dns_client_startrequest().
*
* Notes:
*
*\li If the request procedure has not completed, post its CLIENTREQDONE
* event with a result code of #ISC_R_CANCELED.
*
* Requires:
*
*\li 'trans' is a valid transaction ID.
*/
void
dns_client_destroyreqtrans(dns_clientreqtrans_t **transp);
/*%
* Destroy DNS request transaction state identified by '*transp'.
*
* Requires:
*
*\li '*transp' is a valid transaction ID.
*
*\li The caller has received the CLIENTREQDONE event (either because the
* request completed or because dns_client_cancelrequest() was called).
*
* Ensures:
*
*\li *transp == NULL.
*/
ISC_LANG_ENDDECLS
#endif /* DNS_CLIENT_H */

View file

@ -40,7 +40,7 @@ struct dns_dyndbctx {
dns_zonemgr_t * zmgr;
isc_task_t * task;
isc_timermgr_t *timermgr;
bool * refvar;
const bool * refvar;
};
#define DNS_DYNDBCTX_MAGIC ISC_MAGIC('D', 'd', 'b', 'c')

View file

@ -45,7 +45,6 @@ libisc_la_HEADERS = \
include/isc/iterated_hash.h \
include/isc/lang.h \
include/isc/lex.h \
include/isc/lib.h \
include/isc/likely.h \
include/isc/list.h \
include/isc/log.h \

View file

@ -36,8 +36,8 @@
#include <isc/util.h>
/*%
* For BIND9 internal applications built with threads, we use a single app
* context and let multiple worker, I/O, timer threads do actual jobs.
* For BIND9 applications built with threads, we use a single app
* context and let multiple taskmgr and netmgr threads do actual jobs.
*/
static isc_thread_t blockedthread;
@ -206,13 +206,6 @@ isc_app_ctxrun(isc_appctx_t *ctx) {
UNLOCK(&ctx->lock);
}
/*
* BIND9 internal tools using multiple contexts do not
* rely on signal. */
if (isc_bind9 && ctx != &isc_g_appctx) {
return (ISC_R_SUCCESS);
}
/*
* There is no danger if isc_app_shutdown() is called before we
* wait for signals. Signals are blocked, so any such signal will
@ -220,11 +213,10 @@ isc_app_ctxrun(isc_appctx_t *ctx) {
* sigwait().
*/
while (!atomic_load_acquire(&ctx->want_shutdown)) {
if (isc_bind9) {
if (ctx == &isc_g_appctx) {
sigset_t sset;
int sig;
/*
* BIND9 internal; single context:
* Wait for SIGHUP, SIGINT, or SIGTERM.
*/
if (sigemptyset(&sset) != 0 ||
@ -257,8 +249,9 @@ isc_app_ctxrun(isc_appctx_t *ctx) {
}
} else {
/*
* External, or BIND9 using multiple contexts:
* wait until woken up.
* Tools using multiple contexts don't
* rely on a signal, just wait until woken
* up.
*/
if (atomic_load_acquire(&ctx->want_shutdown)) {
break;
@ -314,11 +307,12 @@ isc_app_ctxshutdown(isc_appctx_t *ctx) {
if (atomic_compare_exchange_strong_acq_rel(&ctx->shutdown_requested,
&(bool){ false }, true))
{
if (isc_bind9 && ctx != &isc_g_appctx) {
/* BIND9 internal, but using multiple contexts */
if (ctx != &isc_g_appctx) {
/* Tool using multiple contexts */
atomic_store_release(&ctx->want_shutdown, true);
} else if (isc_bind9) {
/* BIND9 internal, single context */
SIGNAL(&ctx->ready);
} else {
/* Normal single BIND9 context */
if (kill(getpid(), SIGTERM) < 0) {
char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strbuf, sizeof(strbuf));
@ -327,10 +321,6 @@ isc_app_ctxshutdown(isc_appctx_t *ctx) {
"kill: %s",
strbuf);
}
} else {
/* External, multiple contexts */
atomic_store_release(&ctx->want_shutdown, true);
SIGNAL(&ctx->ready);
}
}
}
@ -350,11 +340,12 @@ isc_app_ctxsuspend(isc_appctx_t *ctx) {
* Don't send the reload signal if we're shutting down.
*/
if (!atomic_load_acquire(&ctx->shutdown_requested)) {
if (isc_bind9 && ctx != &isc_g_appctx) {
/* BIND9 internal, but using multiple contexts */
if (ctx != &isc_g_appctx) {
/* Tool using multiple contexts */
atomic_store_release(&ctx->want_reload, true);
} else if (isc_bind9) {
/* BIND9 internal, single context */
SIGNAL(&ctx->ready);
} else {
/* Normal single BIND9 context */
if (kill(getpid(), SIGHUP) < 0) {
char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strbuf, sizeof(strbuf));
@ -363,10 +354,6 @@ isc_app_ctxsuspend(isc_appctx_t *ctx) {
"kill: %s",
strbuf);
}
} else {
/* External, multiple contexts */
atomic_store_release(&ctx->want_reload, true);
SIGNAL(&ctx->ready);
}
}
}

View file

@ -15,11 +15,4 @@
#include <isc/bind9.h>
/*
* This determines whether we are using the libisc/libdns libraries
* in BIND9 or in some other application. It is initialized to true
* and remains unchanged for BIND9 and related tools; export library
* clients will run isc_lib_register(), which sets it to false,
* overriding certain BIND9 behaviors.
*/
bool isc_bind9 = true;

View file

@ -9,17 +9,8 @@
* information regarding copyright ownership.
*/
#ifndef ISC_BIND9_H
#define ISC_BIND9_H 1
#pragma once
#include <stdbool.h>
/*
* This determines whether we are using the libisc/libdns libraries
* in BIND9 or in some other application. For BIND9 (named and related
* tools) it must be set to true at runtime. Export library clients
* will call isc_lib_register(), which will set it to false.
*/
extern bool isc_bind9;
#endif /* ISC_BIND9_H */

View file

@ -1,33 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#ifndef ISC_LIB_H
#define ISC_LIB_H 1
/*! \file isc/lib.h */
#include <isc/lang.h>
#include <isc/types.h>
ISC_LANG_BEGINDECLS
void
isc_lib_register(void);
/*!<
* \brief Register the ISC library implementations for some base services
* such as memory or event management and handling socket or timer events.
* An external application that wants to use the ISC library must call this
* function very early in main().
*/
ISC_LANG_ENDDECLS
#endif /* ISC_LIB_H */

View file

@ -12,7 +12,6 @@
/*! \file */
#include <isc/bind9.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/os.h>
#include <isc/tls.h>
@ -31,11 +30,6 @@
*** Functions
***/
void
isc_lib_register(void) {
isc_bind9 = false;
}
void
isc__initialize(void) ISC_CONSTRUCTOR;
void

View file

@ -14,7 +14,6 @@
#include <stddef.h>
#include <stdlib.h>
#include <isc/lib.h>
#include <isc/once.h>
#include <isc/resultclass.h>
#include <isc/rwlock.h>

View file

@ -1723,7 +1723,6 @@
./lib/isc/include/isc/iterated_hash.h C 2008,2014,2016,2018,2019,2020,2021
./lib/isc/include/isc/lang.h C 1999,2000,2001,2004,2005,2006,2007,2016,2018,2019,2020,2021
./lib/isc/include/isc/lex.h C 1998,1999,2000,2001,2002,2004,2005,2007,2008,2015,2016,2017,2018,2019,2020,2021
./lib/isc/include/isc/lib.h C 1999,2000,2001,2004,2005,2006,2007,2009,2016,2018,2019,2020,2021
./lib/isc/include/isc/likely.h C 2017,2018,2019,2020,2021
./lib/isc/include/isc/list.h C 1997,1998,1999,2000,2001,2002,2004,2006,2007,2011,2012,2013,2016,2018,2019,2020,2021
./lib/isc/include/isc/log.h C 1999,2000,2001,2002,2004,2005,2006,2007,2009,2014,2016,2017,2018,2019,2020,2021