mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 10:10:06 +00:00
clean up dns_client API
- removed unused functions - changed some public functions to static that are never called from outside client.c - removed unused types and function prototypes - renamed dns_client_destroy() to dns_client_detach()
This commit is contained in:
parent
cdf9a1fd20
commit
556ffe3eea
@ -1844,7 +1844,7 @@ cleanup:
|
|||||||
dns_master_styledestroy(&style, mctx);
|
dns_master_styledestroy(&style, mctx);
|
||||||
}
|
}
|
||||||
if (client != NULL) {
|
if (client != NULL) {
|
||||||
dns_client_destroy(&client);
|
dns_client_detach(&client);
|
||||||
}
|
}
|
||||||
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr);
|
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr);
|
||||||
if (actx != NULL) {
|
if (actx != NULL) {
|
||||||
|
@ -493,7 +493,7 @@ main(int argc, char *argv[]) {
|
|||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
cleanup:
|
cleanup:
|
||||||
if (client != NULL) {
|
if (client != NULL) {
|
||||||
dns_client_destroy(&client);
|
dns_client_detach(&client);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxs_destroy();
|
ctxs_destroy();
|
||||||
|
@ -153,6 +153,10 @@ typedef struct resarg {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
client_resfind(resctx_t *rctx, dns_fetchevent_t *event);
|
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.
|
* Try honoring the operating system's preferred ephemeral port range.
|
||||||
@ -406,7 +410,7 @@ cleanup_lock:
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
destroyclient(dns_client_t *client) {
|
destroyclient(dns_client_t *client) {
|
||||||
dns_view_t *view;
|
dns_view_t *view = NULL;
|
||||||
|
|
||||||
isc_refcount_destroy(&client->references);
|
isc_refcount_destroy(&client->references);
|
||||||
|
|
||||||
@ -433,13 +437,14 @@ destroyclient(dns_client_t *client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dns_client_destroy(dns_client_t **clientp) {
|
dns_client_detach(dns_client_t **clientp) {
|
||||||
dns_client_t *client;
|
dns_client_t *client = NULL;
|
||||||
|
|
||||||
REQUIRE(clientp != NULL);
|
REQUIRE(clientp != NULL);
|
||||||
|
REQUIRE(DNS_CLIENT_VALID(*clientp));
|
||||||
|
|
||||||
client = *clientp;
|
client = *clientp;
|
||||||
*clientp = NULL;
|
*clientp = NULL;
|
||||||
REQUIRE(DNS_CLIENT_VALID(client));
|
|
||||||
|
|
||||||
if (isc_refcount_decrement(&client->references) == 1) {
|
if (isc_refcount_decrement(&client->references) == 1) {
|
||||||
destroyclient(client);
|
destroyclient(client);
|
||||||
@ -974,7 +979,8 @@ static void
|
|||||||
resolve_done(isc_task_t *task, isc_event_t *event) {
|
resolve_done(isc_task_t *task, isc_event_t *event) {
|
||||||
resarg_t *resarg = event->ev_arg;
|
resarg_t *resarg = event->ev_arg;
|
||||||
dns_clientresevent_t *rev = (dns_clientresevent_t *)event;
|
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;
|
isc_result_t result;
|
||||||
|
|
||||||
UNUSED(task);
|
UNUSED(task);
|
||||||
@ -988,8 +994,9 @@ resolve_done(isc_task_t *task, isc_event_t *event) {
|
|||||||
ISC_LIST_APPEND(*resarg->namelist, name, link);
|
ISC_LIST_APPEND(*resarg->namelist, name, link);
|
||||||
}
|
}
|
||||||
|
|
||||||
dns_client_destroyrestrans(&resarg->trans);
|
destroyrestrans(&resarg->trans);
|
||||||
isc_event_free(&event);
|
isc_event_free(&event);
|
||||||
|
resarg->client = NULL;
|
||||||
|
|
||||||
if (!resarg->canceled) {
|
if (!resarg->canceled) {
|
||||||
UNLOCK(&resarg->lock);
|
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
|
* action to call isc_app_ctxsuspend when we do start
|
||||||
* running.
|
* running.
|
||||||
*/
|
*/
|
||||||
result = isc_app_ctxonrun(resarg->actx, resarg->client->mctx,
|
result = isc_app_ctxonrun(resarg->actx, client->mctx, task,
|
||||||
task, suspend, resarg->actx);
|
suspend, resarg->actx);
|
||||||
if (result == ISC_R_ALREADYRUNNING) {
|
if (result == ISC_R_ALREADYRUNNING) {
|
||||||
isc_app_ctxsuspend(resarg->actx);
|
isc_app_ctxsuspend(resarg->actx);
|
||||||
}
|
}
|
||||||
@ -1012,8 +1019,10 @@ resolve_done(isc_task_t *task, isc_event_t *event) {
|
|||||||
*/
|
*/
|
||||||
UNLOCK(&resarg->lock);
|
UNLOCK(&resarg->lock);
|
||||||
isc_mutex_destroy(&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
|
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,
|
dns_rdataclass_t rdclass, dns_rdatatype_t type,
|
||||||
unsigned int options, dns_namelist_t *namelist) {
|
unsigned int options, dns_namelist_t *namelist) {
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
resarg_t *resarg;
|
resarg_t *resarg = NULL;
|
||||||
|
|
||||||
REQUIRE(DNS_CLIENT_VALID(client));
|
REQUIRE(DNS_CLIENT_VALID(client));
|
||||||
REQUIRE(client->actx != NULL);
|
REQUIRE(client->actx != NULL);
|
||||||
@ -1071,7 +1080,7 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name,
|
|||||||
* tricky cleanup process.
|
* tricky cleanup process.
|
||||||
*/
|
*/
|
||||||
resarg->canceled = true;
|
resarg->canceled = true;
|
||||||
dns_client_cancelresolve(resarg->trans);
|
cancelresolve(resarg->trans);
|
||||||
|
|
||||||
UNLOCK(&resarg->lock);
|
UNLOCK(&resarg->lock);
|
||||||
|
|
||||||
@ -1194,9 +1203,16 @@ cleanup:
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/*%<
|
||||||
dns_client_cancelresolve(dns_clientrestrans_t *trans) {
|
* Cancel an ongoing resolution procedure started via
|
||||||
resctx_t *rctx;
|
* 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);
|
REQUIRE(trans != NULL);
|
||||||
rctx = (resctx_t *)trans;
|
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) {
|
* Destroy name resolution transaction state identified by '*transp'.
|
||||||
resctx_t *rctx;
|
*
|
||||||
isc_mem_t *mctx;
|
* The caller must have received the CLIENTRESDONE event (either because the
|
||||||
dns_client_t *client;
|
* 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);
|
REQUIRE(transp != NULL);
|
||||||
|
|
||||||
rctx = (resctx_t *)*transp;
|
rctx = (resctx_t *)*transp;
|
||||||
*transp = NULL;
|
*transp = NULL;
|
||||||
|
|
||||||
REQUIRE(RCTX_VALID(rctx));
|
REQUIRE(RCTX_VALID(rctx));
|
||||||
REQUIRE(rctx->fetch == NULL);
|
REQUIRE(rctx->fetch == NULL);
|
||||||
REQUIRE(rctx->event == NULL);
|
REQUIRE(rctx->event == NULL);
|
||||||
|
|
||||||
client = rctx->client;
|
client = rctx->client;
|
||||||
|
|
||||||
REQUIRE(DNS_CLIENT_VALID(client));
|
REQUIRE(DNS_CLIENT_VALID(client));
|
||||||
|
|
||||||
mctx = client->mctx;
|
mctx = client->mctx;
|
||||||
@ -1271,8 +1297,6 @@ dns_client_destroyrestrans(dns_clientrestrans_t **transp) {
|
|||||||
rctx->magic = 0;
|
rctx->magic = 0;
|
||||||
|
|
||||||
isc_mem_put(mctx, rctx, sizeof(*rctx));
|
isc_mem_put(mctx, rctx, sizeof(*rctx));
|
||||||
|
|
||||||
dns_client_destroy(&client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
|
@ -46,15 +46,6 @@
|
|||||||
|
|
||||||
#include <dst/dst.h>
|
#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
|
ISC_LANG_BEGINDECLS
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@ -75,22 +66,6 @@ ISC_LANG_BEGINDECLS
|
|||||||
/*%< Use TCP transport. */
|
/*%< Use TCP transport. */
|
||||||
#define DNS_CLIENTRESOPT_TCP 0x10
|
#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.
|
* View name used in dns_client.
|
||||||
*/
|
*/
|
||||||
@ -112,20 +87,6 @@ typedef struct dns_clientresevent {
|
|||||||
dns_namelist_t answerlist;
|
dns_namelist_t answerlist;
|
||||||
} dns_clientresevent_t; /* too long? */
|
} 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
|
isc_result_t
|
||||||
dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
||||||
isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr,
|
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
|
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:
|
* Requires:
|
||||||
*
|
*
|
||||||
@ -292,39 +253,6 @@ dns_client_startresolve(dns_client_t *client, const dns_name_t *name,
|
|||||||
*\li Anything else Failure.
|
*\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
|
void
|
||||||
dns_client_freeresanswer(dns_client_t *client, dns_namelist_t *namelist);
|
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.
|
*\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
|
ISC_LANG_ENDDECLS
|
||||||
|
|
||||||
#endif /* DNS_CLIENT_H */
|
#endif /* DNS_CLIENT_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user