]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
clean up dns_client API
authorEvan Hunt <each@isc.org>
Thu, 12 Aug 2021 20:51:47 +0000 (13:51 -0700)
committerOndřej Surý <ondrej@sury.org>
Mon, 30 Aug 2021 06:47:39 +0000 (08:47 +0200)
- 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()

bin/delv/delv.c
bin/tests/system/resolve.c
lib/dns/client.c
lib/dns/include/dns/client.h

index aefe3b94dc11c44fac8533b724c80f53c70baba5..dd1181076b3b6ac22e1c8b96f388c323cbd3353b 100644 (file)
@@ -1844,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) {
index cf95ffd9ce2800c9d76fb02748a25369682f5f05..c13cb5bee4160c7349573b5498c9a426ea31ecd4 100644 (file)
@@ -493,7 +493,7 @@ main(int argc, char *argv[]) {
        /* Cleanup */
 cleanup:
        if (client != NULL) {
-               dns_client_destroy(&client);
+               dns_client_detach(&client);
        }
 
        ctxs_destroy();
index 88244727f1b7a103ee09eef92e482df315c6d85e..78b1efcf4ebdc9026c7ef2f7e2baf1a511e16739 100644 (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
index 79fb13b5a10be4288faaecc92c51bffdd0b3a1dd..d8fcfd3c9e9ba492e3942f3e1d3a83e9f6619433 100644 (file)
 
 #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 */