diff options
author | 2020-02-18 18:11:27 +0000 | |
---|---|---|
committer | 2020-02-18 18:11:27 +0000 | |
commit | 8b5538545d486ecceb041780b03e8ef5e76cedd6 (patch) | |
tree | 97ecca45f41f25f5899a36b8e5e57742e8985ed8 | |
parent | Remove unused task, taskmgr, app, socket and socketmgr methods. (diff) | |
download | wireguard-openbsd-8b5538545d486ecceb041780b03e8ef5e76cedd6.tar.xz wireguard-openbsd-8b5538545d486ecceb041780b03e8ef5e76cedd6.zip |
Get rid of ISC_MAGIC and ISC_MAGIC_VALID macros.
While pulling on that it turns out we can / need git rid of a isc_task
-> isc__task, isc_taskmgr -> isc__taskmgr, isc_timer -> isc__timer and
isc_socket -> isc__socket indirection.
OK millert
42 files changed, 296 insertions, 1720 deletions
diff --git a/usr.bin/dig/dig.c b/usr.bin/dig/dig.c index 41fd7d7485f..104d689b5e8 100644 --- a/usr.bin/dig/dig.c +++ b/usr.bin/dig/dig.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dig.c,v 1.10 2020/02/17 18:58:39 jung Exp $ */ +/* $Id: dig.c,v 1.11 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ #include <sys/cdefs.h> @@ -1940,7 +1940,6 @@ dig_shutdown() { cancel_all(); destroy_libs(); - isc_app_finish(); } /*% Main processing routine for dig */ diff --git a/usr.bin/dig/host.c b/usr.bin/dig/host.c index fb3b6532d6f..123a0ccf632 100644 --- a/usr.bin/dig/host.c +++ b/usr.bin/dig/host.c @@ -843,6 +843,5 @@ host_main(int argc, char **argv) { isc_app_run(); cancel_all(); destroy_libs(); - isc_app_finish(); return ((seen_error == 0) ? 0 : 1); } diff --git a/usr.bin/dig/lib/dns/compress.c b/usr.bin/dig/lib/dns/compress.c index f184567916b..9d1f154f45b 100644 --- a/usr.bin/dig/lib/dns/compress.c +++ b/usr.bin/dig/lib/dns/compress.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: compress.c,v 1.4 2020/02/13 10:12:49 florian Exp $ */ +/* $Id: compress.c,v 1.5 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -25,12 +25,6 @@ #include <dns/compress.h> #include <dns/fixedname.h> -#define CCTX_MAGIC ISC_MAGIC('C', 'C', 'T', 'X') -#define VALID_CCTX(x) ISC_MAGIC_VALID(x, CCTX_MAGIC) - -#define DCTX_MAGIC ISC_MAGIC('D', 'C', 'T', 'X') -#define VALID_DCTX(x) ISC_MAGIC_VALID(x, DCTX_MAGIC) - /*** *** Compression ***/ @@ -46,7 +40,6 @@ dns_compress_init(dns_compress_t *cctx, int edns) { for (i = 0; i < DNS_COMPRESS_TABLESIZE; i++) cctx->table[i] = NULL; cctx->count = 0; - cctx->magic = CCTX_MAGIC; return (ISC_R_SUCCESS); } @@ -55,9 +48,6 @@ dns_compress_invalidate(dns_compress_t *cctx) { dns_compressnode_t *node; unsigned int i; - REQUIRE(VALID_CCTX(cctx)); - - cctx->magic = 0; for (i = 0; i < DNS_COMPRESS_TABLESIZE; i++) { while (cctx->table[i] != NULL) { node = cctx->table[i]; @@ -73,15 +63,12 @@ dns_compress_invalidate(dns_compress_t *cctx) { void dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed) { - REQUIRE(VALID_CCTX(cctx)); - cctx->allowed &= ~DNS_COMPRESS_ALL; cctx->allowed |= (allowed & DNS_COMPRESS_ALL); } unsigned int dns_compress_getmethods(dns_compress_t *cctx) { - REQUIRE(VALID_CCTX(cctx)); return (cctx->allowed & DNS_COMPRESS_ALL); } @@ -106,7 +93,6 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, dns_compressnode_t *node = NULL; unsigned int labels, hash, n; - REQUIRE(VALID_CCTX(cctx)); REQUIRE(dns_name_isabsolute(name) == ISC_TRUE); REQUIRE(offset != NULL); @@ -167,7 +153,6 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, unsigned int tlength; uint16_t toffset; - REQUIRE(VALID_CCTX(cctx)); REQUIRE(dns_name_isabsolute(name)); dns_name_init(&tname, NULL); @@ -213,8 +198,6 @@ dns_compress_rollback(dns_compress_t *cctx, uint16_t offset) { unsigned int i; dns_compressnode_t *node; - REQUIRE(VALID_CCTX(cctx)); - for (i = 0; i < DNS_COMPRESS_TABLESIZE; i++) { node = cctx->table[i]; /* @@ -247,22 +230,10 @@ dns_decompress_init(dns_decompress_t *dctx, int edns, dctx->allowed = DNS_COMPRESS_NONE; dctx->edns = edns; dctx->type = type; - dctx->magic = DCTX_MAGIC; -} - -void -dns_decompress_invalidate(dns_decompress_t *dctx) { - - REQUIRE(VALID_DCTX(dctx)); - - dctx->magic = 0; } void dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed) { - - REQUIRE(VALID_DCTX(dctx)); - switch (dctx->type) { case DNS_DECOMPRESS_ANY: dctx->allowed = DNS_COMPRESS_ALL; diff --git a/usr.bin/dig/lib/dns/dst_api.c b/usr.bin/dig/lib/dns/dst_api.c index e4d3533184c..6f2a110a853 100644 --- a/usr.bin/dig/lib/dns/dst_api.c +++ b/usr.bin/dig/lib/dns/dst_api.c @@ -33,7 +33,7 @@ /* * Principal Author: Brian Wellington - * $Id: dst_api.c,v 1.4 2020/02/12 09:39:53 florian Exp $ + * $Id: dst_api.c,v 1.5 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -180,7 +180,6 @@ dst_context_create4(dst_key_t *key, isc_result_t result; REQUIRE(dst_initialized == ISC_TRUE); - REQUIRE(VALID_KEY(key)); REQUIRE(dctxp != NULL && *dctxp == NULL); if (key->func->createctx == NULL && @@ -209,7 +208,6 @@ dst_context_create4(dst_key_t *key, free(dctx); return (result); } - dctx->magic = CTX_MAGIC; *dctxp = dctx; return (ISC_R_SUCCESS); } @@ -218,21 +216,19 @@ void dst_context_destroy(dst_context_t **dctxp) { dst_context_t *dctx; - REQUIRE(dctxp != NULL && VALID_CTX(*dctxp)); + REQUIRE(dctxp != NULL); dctx = *dctxp; INSIST(dctx->key->func->destroyctx != NULL); dctx->key->func->destroyctx(dctx); if (dctx->key != NULL) dst_key_free(&dctx->key); - dctx->magic = 0; free(dctx); *dctxp = NULL; } isc_result_t dst_context_adddata(dst_context_t *dctx, const isc_region_t *data) { - REQUIRE(VALID_CTX(dctx)); REQUIRE(data != NULL); INSIST(dctx->key->func->adddata != NULL); @@ -243,7 +239,6 @@ isc_result_t dst_context_sign(dst_context_t *dctx, isc_buffer_t *sig) { dst_key_t *key; - REQUIRE(VALID_CTX(dctx)); REQUIRE(sig != NULL); key = dctx->key; @@ -262,7 +257,6 @@ dst_context_sign(dst_context_t *dctx, isc_buffer_t *sig) { isc_result_t dst_context_verify(dst_context_t *dctx, isc_region_t *sig) { - REQUIRE(VALID_CTX(dctx)); REQUIRE(sig != NULL); CHECKALG(dctx->key->key_alg); @@ -278,7 +272,6 @@ isc_result_t dst_context_verify2(dst_context_t *dctx, unsigned int maxbits, isc_region_t *sig) { - REQUIRE(VALID_CTX(dctx)); REQUIRE(sig != NULL); CHECKALG(dctx->key->key_alg); @@ -398,7 +391,6 @@ dst_key_fromnamedfile(const char *filename, const char *dirname, isc_result_t dst_key_todns(const dst_key_t *key, isc_buffer_t *target) { REQUIRE(dst_initialized == ISC_TRUE); - REQUIRE(VALID_KEY(key)); REQUIRE(target != NULL); CHECKALG(key->key_alg); @@ -499,7 +491,6 @@ dst_key_attach(dst_key_t *source, dst_key_t **target) { REQUIRE(dst_initialized == ISC_TRUE); REQUIRE(target != NULL && *target == NULL); - REQUIRE(VALID_KEY(source)); isc_refcount_increment(&source->refs, NULL); *target = source; @@ -511,7 +502,7 @@ dst_key_free(dst_key_t **keyp) { unsigned int refs; REQUIRE(dst_initialized == ISC_TRUE); - REQUIRE(keyp != NULL && VALID_KEY(*keyp)); + REQUIRE(keyp != NULL); key = *keyp; @@ -541,7 +532,6 @@ dst_key_free(dst_key_t **keyp) { isc_result_t dst_key_sigsize(const dst_key_t *key, unsigned int *n) { REQUIRE(dst_initialized == ISC_TRUE); - REQUIRE(VALID_KEY(key)); REQUIRE(n != NULL); /* XXXVIX this switch statement is too sparse to gen a jump table. */ @@ -626,7 +616,6 @@ get_key_struct(dns_name_t *name, unsigned int alg, key->timeset[i] = ISC_FALSE; } key->inactive = ISC_FALSE; - key->magic = KEY_MAGIC; return (key); } diff --git a/usr.bin/dig/lib/dns/dst_internal.h b/usr.bin/dig/lib/dns/dst_internal.h index a750cfa6aea..6ccd14662c8 100644 --- a/usr.bin/dig/lib/dns/dst_internal.h +++ b/usr.bin/dig/lib/dns/dst_internal.h @@ -31,14 +31,12 @@ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dst_internal.h,v 1.5 2020/02/16 21:12:41 florian Exp $ */ +/* $Id: dst_internal.h,v 1.6 2020/02/18 18:11:27 florian Exp $ */ #ifndef DST_DST_INTERNAL_H #define DST_DST_INTERNAL_H 1 #include <isc/buffer.h> - -#include <isc/magic.h> #include <isc/region.h> #include <isc/types.h> #include <isc/refcount.h> @@ -47,7 +45,6 @@ #include <isc/hmacsha.h> #include <dns/time.h> - #include <dst/dst.h> #include <openssl/err.h> @@ -55,12 +52,6 @@ #include <openssl/objects.h> #include <openssl/rsa.h> -#define KEY_MAGIC ISC_MAGIC('D','S','T','K') -#define CTX_MAGIC ISC_MAGIC('D','S','T','C') - -#define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC) -#define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC) - /*** *** Types ***/ @@ -81,7 +72,6 @@ typedef enum { DO_SIGN, DO_VERIFY } dst_use_t; /*% DST Key Structure */ struct dst_key { - unsigned int magic; isc_refcount_t refs; dns_name_t * key_name; /*%< name of the key */ unsigned int key_size; /*%< size of the key in bits */ @@ -123,7 +113,6 @@ struct dst_key { }; struct dst_context { - unsigned int magic; dst_use_t use; dst_key_t *key; isc_logcategory_t *category; diff --git a/usr.bin/dig/lib/dns/include/dns/callbacks.h b/usr.bin/dig/lib/dns/include/dns/callbacks.h index aa5844472d0..e5fe2e95101 100644 --- a/usr.bin/dig/lib/dns/include/dns/callbacks.h +++ b/usr.bin/dig/lib/dns/include/dns/callbacks.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: callbacks.h,v 1.3 2020/02/13 13:53:00 jsg Exp $ */ +/* $Id: callbacks.h,v 1.4 2020/02/18 18:11:27 florian Exp $ */ #ifndef DNS_CALLBACKS_H #define DNS_CALLBACKS_H 1 @@ -25,20 +25,13 @@ *** Imports ***/ -#include <isc/magic.h> - #include <dns/types.h> /*** *** Types ***/ -#define DNS_CALLBACK_MAGIC ISC_MAGIC('C','L','L','B') -#define DNS_CALLBACK_VALID(cb) ISC_MAGIC_VALID(cb, DNS_CALLBACK_MAGIC) - struct dns_rdatacallbacks { - unsigned int magic; - /*% * dns_load_master calls this when it has rdatasets to commit. */ diff --git a/usr.bin/dig/lib/dns/include/dns/compress.h b/usr.bin/dig/lib/dns/include/dns/compress.h index 4d2b628c70f..41f1c6bc3c0 100644 --- a/usr.bin/dig/lib/dns/include/dns/compress.h +++ b/usr.bin/dig/lib/dns/include/dns/compress.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: compress.h,v 1.3 2020/02/13 13:53:00 jsg Exp $ */ +/* $Id: compress.h,v 1.4 2020/02/18 18:11:27 florian Exp $ */ #ifndef DNS_COMPRESS_H #define DNS_COMPRESS_H 1 @@ -46,7 +46,6 @@ struct dns_compressnode { }; struct dns_compress { - unsigned int magic; /*%< Magic number. */ unsigned int allowed; /*%< Allowed methods. */ int edns; /*%< Edns version or -1. */ /*% Global compression table. */ @@ -63,7 +62,6 @@ typedef enum { } dns_decompresstype_t; struct dns_decompress { - unsigned int magic; /*%< Magic number. */ unsigned int allowed; /*%< Allowed methods. */ int edns; /*%< Edns version or -1. */ dns_decompresstype_t type; /*%< Strict checking */ diff --git a/usr.bin/dig/lib/dns/include/dns/message.h b/usr.bin/dig/lib/dns/include/dns/message.h index 9cb13e11040..745d4cca278 100644 --- a/usr.bin/dig/lib/dns/include/dns/message.h +++ b/usr.bin/dig/lib/dns/include/dns/message.h @@ -21,8 +21,6 @@ *** Imports ***/ -#include <isc/magic.h> - #include <dns/compress.h> #include <dns/masterdump.h> #include <dns/types.h> @@ -115,9 +113,6 @@ #define DNS_MESSAGE_HEADERLEN 12 /*%< 6 uint16_t's */ -#define DNS_MESSAGE_MAGIC ISC_MAGIC('M','S','G','@') -#define DNS_MESSAGE_VALID(msg) ISC_MAGIC_VALID(msg, DNS_MESSAGE_MAGIC) - /* * Ordering here matters. DNS_SECTION_ANY must be the lowest and negative, * and DNS_SECTION_MAX must be one greater than the last used section. @@ -184,8 +179,6 @@ typedef struct dns_msgblock dns_msgblock_t; struct dns_message { /* public from here down */ - unsigned int magic; - dns_messageid_t id; unsigned int flags; dns_rcode_t rcode; diff --git a/usr.bin/dig/lib/dns/include/dns/name.h b/usr.bin/dig/lib/dns/include/dns/name.h index 891db64ac47..43136f1f2f4 100644 --- a/usr.bin/dig/lib/dns/include/dns/name.h +++ b/usr.bin/dig/lib/dns/include/dns/name.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: name.h,v 1.5 2020/02/13 16:55:20 florian Exp $ */ +/* $Id: name.h,v 1.6 2020/02/18 18:11:27 florian Exp $ */ #ifndef DNS_NAME_H #define DNS_NAME_H 1 @@ -73,7 +73,6 @@ #include <stdio.h> #include <isc/boolean.h> -#include <isc/magic.h> #include <isc/region.h> /* Required for storage size of dns_label_t. */ #include <dns/types.h> @@ -104,7 +103,6 @@ * for whatever purpose the client desires. */ struct dns_name { - unsigned int magic; unsigned char * ndata; unsigned int length; unsigned int labels; @@ -115,8 +113,6 @@ struct dns_name { ISC_LIST(dns_rdataset_t) list; }; -#define DNS_NAME_MAGIC ISC_MAGIC('D','N','S','n') - #define DNS_NAMEATTR_ABSOLUTE 0x00000001 #define DNS_NAMEATTR_READONLY 0x00000002 #define DNS_NAMEATTR_DYNAMIC 0x00000004 @@ -1103,7 +1099,6 @@ dns_name_isdnssd(const dns_name_t *owner); */ #define DNS_NAME_INITABSOLUTE(A,B) { \ - DNS_NAME_MAGIC, \ A, sizeof(A), sizeof(B), \ DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE, \ B, NULL, { (void *)-1, (void *)-1}, \ @@ -1111,7 +1106,6 @@ dns_name_isdnssd(const dns_name_t *owner); } #define DNS_NAME_INITNONABSOLUTE(A,B) { \ - DNS_NAME_MAGIC, \ A, (sizeof(A) - 1), sizeof(B), \ DNS_NAMEATTR_READONLY, \ B, NULL, { (void *)-1, (void *)-1}, \ diff --git a/usr.bin/dig/lib/dns/include/dns/rdataset.h b/usr.bin/dig/lib/dns/include/dns/rdataset.h index baf39aa3da7..2792e33361c 100644 --- a/usr.bin/dig/lib/dns/include/dns/rdataset.h +++ b/usr.bin/dig/lib/dns/include/dns/rdataset.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdataset.h,v 1.4 2020/02/16 21:12:41 florian Exp $ */ +/* $Id: rdataset.h,v 1.5 2020/02/18 18:11:27 florian Exp $ */ #ifndef DNS_RDATASET_H #define DNS_RDATASET_H 1 @@ -50,8 +50,6 @@ *\li None. */ -#include <isc/magic.h> - #include <dns/types.h> #include "rdatastruct.h" @@ -112,9 +110,6 @@ typedef struct dns_rdatasetmethods { void (*clearprefetch)(dns_rdataset_t *rdataset); } dns_rdatasetmethods_t; -#define DNS_RDATASET_MAGIC ISC_MAGIC('D','N','S','R') -#define DNS_RDATASET_VALID(set) ISC_MAGIC_VALID(set, DNS_RDATASET_MAGIC) - /*% * Direct use of this structure by clients is strongly discouraged, except * for the 'link' field which may be used however the client wishes. The @@ -122,7 +117,6 @@ typedef struct dns_rdatasetmethods { * rdataset implementations may change any of the fields. */ struct dns_rdataset { - unsigned int magic; /* XXX ? */ dns_rdatasetmethods_t * methods; ISC_LINK(dns_rdataset_t) link; /* diff --git a/usr.bin/dig/lib/dns/include/dns/tsig.h b/usr.bin/dig/lib/dns/include/dns/tsig.h index ddbb63482e6..5fd3e945cdd 100644 --- a/usr.bin/dig/lib/dns/include/dns/tsig.h +++ b/usr.bin/dig/lib/dns/include/dns/tsig.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: tsig.h,v 1.4 2020/02/17 19:45:00 jung Exp $ */ +/* $Id: tsig.h,v 1.5 2020/02/18 18:11:27 florian Exp $ */ #ifndef DNS_TSIG_H #define DNS_TSIG_H 1 @@ -49,7 +49,6 @@ extern dns_name_t *dns_tsig_hmacsha512_name; struct dns_tsigkey { /* Unlocked */ - unsigned int magic; /*%< Magic number. */ dst_key_t *key; /*%< Key */ dns_name_t name; /*%< Key name */ dns_name_t *algorithm; /*%< Algorithm name */ diff --git a/usr.bin/dig/lib/dns/key.c b/usr.bin/dig/lib/dns/key.c index 2ffe86ef729..ae14b0aef3a 100644 --- a/usr.bin/dig/lib/dns/key.c +++ b/usr.bin/dig/lib/dns/key.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: key.c,v 1.4 2020/02/12 13:05:03 jsg Exp $ */ +/* $Id: key.c,v 1.5 2020/02/18 18:11:27 florian Exp $ */ @@ -84,26 +84,22 @@ dst_region_computerid(const isc_region_t *source, unsigned int alg) { dns_name_t * dst_key_name(const dst_key_t *key) { - REQUIRE(VALID_KEY(key)); return (key->key_name); } unsigned int dst_key_size(const dst_key_t *key) { - REQUIRE(VALID_KEY(key)); return (key->key_size); } unsigned int dst_key_alg(const dst_key_t *key) { - REQUIRE(VALID_KEY(key)); return (key->key_alg); } void dst_key_setbits(dst_key_t *key, uint16_t bits) { unsigned int maxbits; - REQUIRE(VALID_KEY(key)); if (bits != 0) { RUNTIME_CHECK(dst_key_sigsize(key, &maxbits) == ISC_R_SUCCESS); maxbits *= 8; @@ -114,7 +110,6 @@ dst_key_setbits(dst_key_t *key, uint16_t bits) { uint16_t dst_key_getbits(const dst_key_t *key) { - REQUIRE(VALID_KEY(key)); return (key->key_bits); } diff --git a/usr.bin/dig/lib/dns/masterdump.c b/usr.bin/dig/lib/dns/masterdump.c index 4a3ac2d1b10..f1bf14e3b62 100644 --- a/usr.bin/dig/lib/dns/masterdump.c +++ b/usr.bin/dig/lib/dns/masterdump.c @@ -266,8 +266,6 @@ rdataset_totext(dns_rdataset_t *rdataset, dns_rdatatype_t type; unsigned int type_start; - REQUIRE(DNS_RDATASET_VALID(rdataset)); - rdataset->attributes |= DNS_RDATASETATTR_LOADORDER; result = dns_rdataset_first(rdataset); @@ -437,7 +435,6 @@ question_totext(dns_rdataset_t *rdataset, isc_result_t result; isc_region_t r; - REQUIRE(DNS_RDATASET_VALID(rdataset)); result = dns_rdataset_first(rdataset); REQUIRE(result == ISC_R_NOMORE); diff --git a/usr.bin/dig/lib/dns/message.c b/usr.bin/dig/lib/dns/message.c index 571201e87e4..9481ba30471 100644 --- a/usr.bin/dig/lib/dns/message.c +++ b/usr.bin/dig/lib/dns/message.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: message.c,v 1.6 2020/02/13 12:03:51 jsg Exp $ */ +/* $Id: message.c,v 1.7 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -646,7 +646,6 @@ dns_message_create(unsigned int intent, dns_message_t **msgp) * and other members that are freed in the cleanup phase here. */ - m->magic = DNS_MESSAGE_MAGIC; m->from_to_wire = intent; msginit(m); @@ -685,7 +684,6 @@ dns_message_create(unsigned int intent, dns_message_t **msgp) ISC_LIST_UNLINK(m->scratchpad, dynbuf, link); isc_buffer_free(&dynbuf); } - m->magic = 0; free(m); return (ISC_R_NOMEMORY); @@ -696,13 +694,11 @@ dns_message_destroy(dns_message_t **msgp) { dns_message_t *msg; REQUIRE(msgp != NULL); - REQUIRE(DNS_MESSAGE_VALID(*msgp)); msg = *msgp; *msgp = NULL; msgreset(msg, ISC_TRUE); - msg->magic = 0; free(msg); } @@ -1558,7 +1554,6 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, isc_boolean_t seen_problem; isc_boolean_t ignore_tc; - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(source != NULL); REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE); @@ -1670,7 +1665,6 @@ dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx, { isc_region_t r; - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(buffer != NULL); REQUIRE(msg->buffer == NULL); REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER); @@ -1705,7 +1699,6 @@ dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx, void dns_message_renderrelease(dns_message_t *msg, unsigned int space) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(space <= msg->reserved); msg->reserved -= space; @@ -1715,8 +1708,6 @@ isc_result_t dns_message_renderreserve(dns_message_t *msg, unsigned int space) { isc_region_t r; - REQUIRE(DNS_MESSAGE_VALID(msg)); - if (msg->buffer != NULL) { isc_buffer_availableregion(msg->buffer, &r); if (r.length < (space + msg->reserved)) @@ -1805,7 +1796,6 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, unsigned int rd_options; dns_rdatatype_t preferred_glue = 0; - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(msg->buffer != NULL); REQUIRE(VALID_NAMED_SECTION(sectionid)); @@ -2008,7 +1998,6 @@ dns_message_renderheader(dns_message_t *msg, isc_buffer_t *target) { uint16_t tmp; isc_region_t r; - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(target != NULL); isc_buffer_availableregion(target, &r); @@ -2044,7 +2033,6 @@ dns_message_renderend(dns_message_t *msg) { int result; unsigned int count; - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(msg->buffer != NULL); if ((msg->rcode & ~DNS_MESSAGE_RCODE_MASK) != 0 && msg->opt == NULL) { @@ -2138,7 +2126,6 @@ dns_message_renderreset(dns_message_t *msg) { * Reset the message so that it may be rendered again. */ - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER); msg->buffer = NULL; @@ -2170,7 +2157,6 @@ dns_message_renderreset(dns_message_t *msg) { isc_result_t dns_message_firstname(dns_message_t *msg, dns_section_t section) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(VALID_NAMED_SECTION(section)); msg->cursors[section] = ISC_LIST_HEAD(msg->sections[section]); @@ -2183,7 +2169,6 @@ dns_message_firstname(dns_message_t *msg, dns_section_t section) { isc_result_t dns_message_nextname(dns_message_t *msg, dns_section_t section) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(VALID_NAMED_SECTION(section)); REQUIRE(msg->cursors[section] != NULL); @@ -2199,7 +2184,6 @@ void dns_message_currentname(dns_message_t *msg, dns_section_t section, dns_name_t **name) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(VALID_NAMED_SECTION(section)); REQUIRE(name != NULL && *name == NULL); REQUIRE(msg->cursors[section] != NULL); @@ -2271,7 +2255,6 @@ dns_message_addname(dns_message_t *msg, dns_name_t *name, isc_result_t dns_message_gettempname(dns_message_t *msg, dns_name_t **item) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(item != NULL && *item == NULL); *item = malloc(sizeof(dns_name_t)); @@ -2284,7 +2267,6 @@ dns_message_gettempname(dns_message_t *msg, dns_name_t **item) { isc_result_t dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(item != NULL && *item == NULL); *item = newrdata(msg); @@ -2296,7 +2278,6 @@ dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item) { isc_result_t dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(item != NULL && *item == NULL); *item = malloc(sizeof(dns_rdataset_t)); @@ -2310,7 +2291,6 @@ dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item) { isc_result_t dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(item != NULL && *item == NULL); *item = newrdatalist(msg); @@ -2322,7 +2302,6 @@ dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) { void dns_message_puttempname(dns_message_t *msg, dns_name_t **item) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(item != NULL && *item != NULL); if (dns_name_dynamic(*item)) @@ -2333,7 +2312,6 @@ dns_message_puttempname(dns_message_t *msg, dns_name_t **item) { void dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(item != NULL && *item != NULL); releaserdata(msg, *item); @@ -2342,7 +2320,6 @@ dns_message_puttemprdata(dns_message_t *msg, dns_rdata_t **item) { void dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(item != NULL && *item != NULL); REQUIRE(!dns_rdataset_isassociated(*item)); @@ -2352,7 +2329,6 @@ dns_message_puttemprdataset(dns_message_t *msg, dns_rdataset_t **item) { void dns_message_puttemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(item != NULL && *item != NULL); releaserdatalist(msg, *item); @@ -2394,9 +2370,6 @@ dns_message_getopt(dns_message_t *msg) { /* * Get the OPT record for 'msg'. */ - - REQUIRE(DNS_MESSAGE_VALID(msg)); - return (msg->opt); } @@ -2423,7 +2396,6 @@ dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt) { * plus the length of the rdata. */ - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(opt->type == dns_rdatatype_opt); REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER); REQUIRE(msg->state == DNS_SECTION_ANY); @@ -2458,7 +2430,6 @@ dns_message_gettsig(dns_message_t *msg, dns_name_t **owner) { * Get the TSIG record and owner for 'msg'. */ - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(owner == NULL || *owner == NULL); if (owner != NULL) @@ -2474,7 +2445,6 @@ dns_message_settsigkey(dns_message_t *msg, dns_tsigkey_t *key) { * Set the TSIG key for 'msg' */ - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(msg->state == DNS_SECTION_ANY); if (key == NULL && msg->tsigkey != NULL) { @@ -2507,9 +2477,6 @@ dns_message_gettsigkey(dns_message_t *msg) { /* * Get the TSIG key for 'msg' */ - - REQUIRE(DNS_MESSAGE_VALID(msg)); - return (msg->tsigkey); } @@ -2522,7 +2489,6 @@ dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig) { isc_region_t r; isc_result_t result; - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(msg->querytsig == NULL); if (querytsig == NULL) @@ -2573,7 +2539,6 @@ dns_message_getquerytsig(dns_message_t *msg, isc_buffer_t **querytsig) { dns_rdata_t rdata = DNS_RDATA_INIT; isc_region_t r; - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(querytsig != NULL && *querytsig == NULL); if (msg->tsig == NULL) @@ -2599,7 +2564,6 @@ dns_message_getsig0(dns_message_t *msg, dns_name_t **owner) { * Get the SIG(0) record for 'msg'. */ - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(owner == NULL || *owner == NULL); if (msg->sig0 != NULL && owner != NULL) { @@ -2617,9 +2581,7 @@ dns_message_getsig0(dns_message_t *msg, dns_name_t **owner) { void dns_message_takebuffer(dns_message_t *msg, isc_buffer_t **buffer) { - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(buffer != NULL); - REQUIRE(ISC_BUFFER_VALID(*buffer)); ISC_LIST_APPEND(msg->cleanup, *buffer, link); *buffer = NULL; @@ -2635,7 +2597,6 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, isc_result_t result; isc_boolean_t seensoa = ISC_FALSE; - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(target != NULL); REQUIRE(VALID_SECTION(section)); @@ -2769,7 +2730,6 @@ dns_message_pseudosectiontotext(dns_message_t *msg, uint16_t optcode, optlen; unsigned char *optdata; - REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(target != NULL); REQUIRE(VALID_PSEUDOSECTION(section)); @@ -2975,7 +2935,6 @@ dns_message_buildopt(dns_message_t *message, dns_rdataset_t **rdatasetp, isc_result_t result; unsigned int len = 0, i; - REQUIRE(DNS_MESSAGE_VALID(message)); REQUIRE(rdatasetp != NULL && *rdatasetp == NULL); result = dns_message_gettemprdatalist(message, &rdatalist); diff --git a/usr.bin/dig/lib/dns/name.c b/usr.bin/dig/lib/dns/name.c index f790d9f1da9..778e62b3056 100644 --- a/usr.bin/dig/lib/dns/name.c +++ b/usr.bin/dig/lib/dns/name.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: name.c,v 1.7 2020/02/15 10:56:25 florian Exp $ */ +/* $Id: name.c,v 1.8 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ #include <ctype.h> @@ -30,8 +30,6 @@ #include <dns/name.h> #include <dns/result.h> -#define VALID_NAME(n) ISC_MAGIC_VALID(n, DNS_NAME_MAGIC) - typedef enum { ft_init = 0, ft_start, @@ -166,7 +164,6 @@ dns_name_init(dns_name_t *name, unsigned char *offsets) { /* * Initialize 'name'. */ - name->magic = DNS_NAME_MAGIC; name->ndata = NULL; name->length = 0; name->labels = 0; @@ -180,7 +177,6 @@ dns_name_init(dns_name_t *name, unsigned char *offsets) { void dns_name_reset(dns_name_t *name) { - REQUIRE(VALID_NAME(name)); REQUIRE(BINDABLE(name)); name->ndata = NULL; @@ -197,9 +193,7 @@ dns_name_invalidate(dns_name_t *name) { * Make 'name' invalid. */ - REQUIRE(VALID_NAME(name)); - name->magic = 0; name->ndata = NULL; name->length = 0; name->labels = 0; @@ -215,7 +209,6 @@ dns_name_setbuffer(dns_name_t *name, isc_buffer_t *buffer) { * Dedicate a buffer for use with 'name'. */ - REQUIRE(VALID_NAME(name)); REQUIRE((buffer != NULL && name->buffer == NULL) || (buffer == NULL)); @@ -229,7 +222,6 @@ dns_name_isabsolute(const dns_name_t *name) { * Does 'name' end in the root label? */ - REQUIRE(VALID_NAME(name)); if ((name->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) return (ISC_TRUE); @@ -250,7 +242,6 @@ dns_name_ismailbox(const dns_name_t *name) { unsigned int n; isc_boolean_t first; - REQUIRE(VALID_NAME(name)); REQUIRE(name->labels > 0); REQUIRE(name->attributes & DNS_NAMEATTR_ABSOLUTE); @@ -300,7 +291,6 @@ dns_name_ishostname(const dns_name_t *name, isc_boolean_t wildcard) { unsigned int n; isc_boolean_t first; - REQUIRE(VALID_NAME(name)); REQUIRE(name->labels > 0); REQUIRE(name->attributes & DNS_NAMEATTR_ABSOLUTE); @@ -346,7 +336,6 @@ dns_name_hash(dns_name_t *name, isc_boolean_t case_sensitive) { /* * Provide a hash value for 'name'. */ - REQUIRE(VALID_NAME(name)); if (name->labels == 0) return (0); @@ -381,8 +370,6 @@ dns_name_fullcompare(const dns_name_t *name1, const dns_name_t *name2, * same domain. */ - REQUIRE(VALID_NAME(name1)); - REQUIRE(VALID_NAME(name2)); REQUIRE(orderp != NULL); REQUIRE(nlabelsp != NULL); /* @@ -533,8 +520,6 @@ dns_name_equal(const dns_name_t *name1, const dns_name_t *name2) { * same domain. */ - REQUIRE(VALID_NAME(name1)); - REQUIRE(VALID_NAME(name2)); /* * Either name1 is absolute and name2 is absolute, or neither is. */ @@ -601,8 +586,6 @@ dns_name_caseequal(const dns_name_t *name1, const dns_name_t *name2) { * same domain. */ - REQUIRE(VALID_NAME(name1)); - REQUIRE(VALID_NAME(name2)); /* * Either name1 is absolute and name2 is absolute, or neither is. */ @@ -628,10 +611,8 @@ dns_name_rdatacompare(const dns_name_t *name1, const dns_name_t *name2) { * Compare two absolute names as rdata. */ - REQUIRE(VALID_NAME(name1)); REQUIRE(name1->labels > 0); REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) != 0); - REQUIRE(VALID_NAME(name2)); REQUIRE(name2->labels > 0); REQUIRE((name2->attributes & DNS_NAMEATTR_ABSOLUTE) != 0); @@ -705,7 +686,6 @@ dns_name_countlabels(const dns_name_t *name) { * How many labels does 'name' have? */ - REQUIRE(VALID_NAME(name)); ENSURE(name->labels <= 128); @@ -721,7 +701,6 @@ dns_name_getlabel(const dns_name_t *name, unsigned int n, dns_label_t *label) { * Make 'label' refer to the 'n'th least significant label of 'name'. */ - REQUIRE(VALID_NAME(name)); REQUIRE(name->labels > 0); REQUIRE(n < name->labels); REQUIRE(label != NULL); @@ -749,8 +728,6 @@ dns_name_getlabelsequence(const dns_name_t *source, * 'first' in 'source'. */ - REQUIRE(VALID_NAME(source)); - REQUIRE(VALID_NAME(target)); REQUIRE(first <= source->labels); REQUIRE(n <= source->labels - first); /* note first+n could overflow */ REQUIRE(BINDABLE(target)); @@ -795,8 +772,6 @@ dns_name_clone(const dns_name_t *source, dns_name_t *target) { * Make 'target' refer to the same name as 'source'. */ - REQUIRE(VALID_NAME(source)); - REQUIRE(VALID_NAME(target)); REQUIRE(BINDABLE(target)); target->ndata = source->ndata; @@ -825,7 +800,6 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r) { * Make 'name' refer to region 'r'. */ - REQUIRE(VALID_NAME(name)); REQUIRE(r != NULL); REQUIRE(BINDABLE(name)); @@ -864,7 +838,6 @@ dns_name_toregion(dns_name_t *name, isc_region_t *r) { * Make 'r' refer to 'name'. */ - REQUIRE(VALID_NAME(name)); REQUIRE(r != NULL); r->base = name->ndata; @@ -898,11 +871,6 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, * will remain relative. */ - REQUIRE(VALID_NAME(name)); - REQUIRE(ISC_BUFFER_VALID(source)); - REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) || - (target == NULL && ISC_BUFFER_VALID(name->buffer))); - downcase = ISC_TF((options & DNS_NAME_DOWNCASE) != 0); if (target == NULL && name->buffer != NULL) { @@ -1145,8 +1113,6 @@ dns_name_totext2(dns_name_t *name, unsigned int options, isc_buffer_t *target) * This function assumes the name is in proper uncompressed * wire format. */ - REQUIRE(VALID_NAME(name)); - REQUIRE(ISC_BUFFER_VALID(target)); ndata = name->ndata; nlen = name->length; @@ -1299,8 +1265,6 @@ dns_name_downcase(dns_name_t *source, dns_name_t *name, isc_buffer_t *target) { * Downcase 'source'. */ - REQUIRE(VALID_NAME(source)); - REQUIRE(VALID_NAME(name)); if (source == name) { REQUIRE((name->attributes & DNS_NAMEATTR_READONLY) == 0); isc_buffer_init(&buffer, source->ndata, source->length); @@ -1308,8 +1272,6 @@ dns_name_downcase(dns_name_t *source, dns_name_t *name, isc_buffer_t *target) { ndata = source->ndata; } else { REQUIRE(BINDABLE(name)); - REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) || - (target == NULL && ISC_BUFFER_VALID(name->buffer))); if (target == NULL) { target = name->buffer; isc_buffer_clear(name->buffer); @@ -1426,10 +1388,6 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, * the new pointer against biggest_pointer. */ - REQUIRE(VALID_NAME(name)); - REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) || - (target == NULL && ISC_BUFFER_VALID(name->buffer))); - downcase = ISC_TF((options & DNS_NAME_DOWNCASE) != 0); if (target == NULL && name->buffer != NULL) { @@ -1593,9 +1551,7 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx, * compression context 'cctx', and storing the result in 'target'. */ - REQUIRE(VALID_NAME(name)); REQUIRE(cctx != NULL); - REQUIRE(ISC_BUFFER_VALID(target)); /* * If 'name' doesn't have an offsets table, make a clone which @@ -1676,11 +1632,6 @@ dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name, * Concatenate 'prefix' and 'suffix'. */ - REQUIRE(prefix == NULL || VALID_NAME(prefix)); - REQUIRE(suffix == NULL || VALID_NAME(suffix)); - REQUIRE(name == NULL || VALID_NAME(name)); - REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) || - (target == NULL && name != NULL && ISC_BUFFER_VALID(name->buffer))); if (prefix == NULL || prefix->labels == 0) copy_prefix = ISC_FALSE; if (suffix == NULL || suffix->labels == 0) @@ -1769,16 +1720,13 @@ dns_name_split(dns_name_t *name, unsigned int suffixlabels, { unsigned int splitlabel; - REQUIRE(VALID_NAME(name)); REQUIRE(suffixlabels > 0); REQUIRE(suffixlabels < name->labels); REQUIRE(prefix != NULL || suffix != NULL); REQUIRE(prefix == NULL || - (VALID_NAME(prefix) && - BINDABLE(prefix))); + BINDABLE(prefix)); REQUIRE(suffix == NULL || - (VALID_NAME(suffix) && - BINDABLE(suffix))); + BINDABLE(suffix)); splitlabel = name->labels - suffixlabels; @@ -1800,9 +1748,7 @@ dns_name_dup(const dns_name_t *source, * Make 'target' a dynamically allocated copy of 'source'. */ - REQUIRE(VALID_NAME(source)); REQUIRE(source->length > 0); - REQUIRE(VALID_NAME(target)); REQUIRE(BINDABLE(target)); /* @@ -1841,9 +1787,7 @@ dns_name_dupwithoffsets(dns_name_t *source, * 'target' will also have a dynamically allocated offsets table. */ - REQUIRE(VALID_NAME(source)); REQUIRE(source->length > 0); - REQUIRE(VALID_NAME(target)); REQUIRE(BINDABLE(target)); REQUIRE(target->offsets == NULL); @@ -1881,7 +1825,6 @@ dns_name_free(dns_name_t *name) { * Free 'name'. */ - REQUIRE(VALID_NAME(name)); REQUIRE((name->attributes & DNS_NAMEATTR_DYNAMIC) != 0); size = name->length; @@ -1903,7 +1846,6 @@ dns_name_digest(dns_name_t *name, dns_digestfunc_t digest, void *arg) { * Send 'name' in DNSSEC canonical form to 'digest'. */ - REQUIRE(VALID_NAME(name)); REQUIRE(digest != NULL); dns_name_init(&downname, NULL); @@ -1921,7 +1863,6 @@ dns_name_digest(dns_name_t *name, dns_digestfunc_t digest, void *arg) { isc_boolean_t dns_name_dynamic(dns_name_t *name) { - REQUIRE(VALID_NAME(name)); /* * Returns whether there is dynamic memory associated with this name. @@ -2008,8 +1949,6 @@ dns_name_copy(dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) { * Make dest a copy of source. */ - REQUIRE(VALID_NAME(source)); - REQUIRE(VALID_NAME(dest)); REQUIRE(target != NULL || dest->buffer != NULL); if (target == NULL) { diff --git a/usr.bin/dig/lib/dns/rdata.c b/usr.bin/dig/lib/dns/rdata.c index d62e2a98b16..345051b3d87 100644 --- a/usr.bin/dig/lib/dns/rdata.c +++ b/usr.bin/dig/lib/dns/rdata.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdata.c,v 1.7 2020/02/13 16:57:55 florian Exp $ */ +/* $Id: rdata.c,v 1.8 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -815,8 +815,6 @@ rdata_validate(isc_buffer_t *src, isc_buffer_t *dest, dns_rdataclass_t rdclass, dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE); isc_buffer_setactive(src, isc_buffer_usedlength(src)); result = dns_rdata_fromwire(NULL, rdclass, type, src, &dctx, 0, dest); - dns_decompress_invalidate(&dctx); - return (result); } diff --git a/usr.bin/dig/lib/dns/rdatalist.c b/usr.bin/dig/lib/dns/rdatalist.c index 856292f2e41..1c37ca65f39 100644 --- a/usr.bin/dig/lib/dns/rdatalist.c +++ b/usr.bin/dig/lib/dns/rdatalist.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdatalist.c,v 1.1 2020/02/07 09:58:52 florian Exp $ */ +/* $Id: rdatalist.c,v 1.2 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -74,7 +74,6 @@ dns_rdatalist_tordataset(dns_rdatalist_t *rdatalist, */ REQUIRE(rdatalist != NULL); - REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(! dns_rdataset_isassociated(rdataset)); rdataset->methods = &methods; diff --git a/usr.bin/dig/lib/dns/rdataset.c b/usr.bin/dig/lib/dns/rdataset.c index f8f1f1149ea..13e3d487a72 100644 --- a/usr.bin/dig/lib/dns/rdataset.c +++ b/usr.bin/dig/lib/dns/rdataset.c @@ -36,7 +36,6 @@ dns_rdataset_init(dns_rdataset_t *rdataset) { REQUIRE(rdataset != NULL); - rdataset->magic = DNS_RDATASET_MAGIC; rdataset->methods = NULL; ISC_LINK_INIT(rdataset, link); rdataset->rdclass = 0; @@ -63,7 +62,6 @@ dns_rdataset_disassociate(dns_rdataset_t *rdataset) { * Disassociate 'rdataset' from its rdata, allowing it to be reused. */ - REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); (rdataset->methods->disassociate)(rdataset); @@ -90,7 +88,6 @@ dns_rdataset_isassociated(dns_rdataset_t *rdataset) { * Is 'rdataset' associated? */ - REQUIRE(DNS_RDATASET_VALID(rdataset)); if (rdataset->methods != NULL) return (ISC_TRUE); @@ -166,7 +163,6 @@ dns_rdataset_makequestion(dns_rdataset_t *rdataset, dns_rdataclass_t rdclass, * question class of 'rdclass' and type 'type'. */ - REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods == NULL); rdataset->methods = &question_methods; @@ -182,9 +178,7 @@ dns_rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) { * Make 'target' refer to the same rdataset as 'source'. */ - REQUIRE(DNS_RDATASET_VALID(source)); REQUIRE(source->methods != NULL); - REQUIRE(DNS_RDATASET_VALID(target)); REQUIRE(target->methods == NULL); (source->methods->clone)(source, target); @@ -197,7 +191,6 @@ dns_rdataset_first(dns_rdataset_t *rdataset) { * Move the rdata cursor to the first rdata in the rdataset (if any). */ - REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); return ((rdataset->methods->first)(rdataset)); @@ -210,7 +203,6 @@ dns_rdataset_next(dns_rdataset_t *rdataset) { * Move the rdata cursor to the next rdata in the rdataset (if any). */ - REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); return ((rdataset->methods->next)(rdataset)); @@ -223,7 +215,6 @@ dns_rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) { * Make 'rdata' refer to the current rdata. */ - REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); (rdataset->methods->current)(rdataset, rdata); @@ -270,7 +261,6 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name, * in cctx, and storing the result in 'target'. */ - REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); REQUIRE(countp != NULL); REQUIRE((order == NULL) == (order_arg == NULL)); diff --git a/usr.bin/dig/lib/dns/tsig.c b/usr.bin/dig/lib/dns/tsig.c index ded797a7c2e..525b245d05a 100644 --- a/usr.bin/dig/lib/dns/tsig.c +++ b/usr.bin/dig/lib/dns/tsig.c @@ -15,7 +15,7 @@ */ /* - * $Id: tsig.c,v 1.7 2020/02/16 21:12:41 florian Exp $ + * $Id: tsig.c,v 1.8 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -39,9 +39,6 @@ #include <dst/result.h> -#define TSIG_MAGIC ISC_MAGIC('T', 'S', 'I', 'G') -#define VALID_TSIG_KEY(x) ISC_MAGIC_VALID(x, TSIG_MAGIC) - #define is_response(msg) (msg->flags & DNS_MESSAGEFLAG_QR) #define algname_is_allocated(algname) \ ((algname) != dns_tsig_hmacsha1_name && \ @@ -237,8 +234,6 @@ dns_tsigkey_createfromkey(dns_name_t *name, dns_name_t *algorithm, tkey->expire = expire; ISC_LINK_INIT(tkey, link); - tkey->magic = TSIG_MAGIC; - /* * Ignore this if it's a GSS key, since the key size is meaningless. */ @@ -374,7 +369,6 @@ dns_tsigkey_create(dns_name_t *name, dns_name_t *algorithm, void dns_tsigkey_attach(dns_tsigkey_t *source, dns_tsigkey_t **targetp) { - REQUIRE(VALID_TSIG_KEY(source)); REQUIRE(targetp != NULL && *targetp == NULL); isc_refcount_increment(&source->refs, NULL); @@ -383,9 +377,6 @@ dns_tsigkey_attach(dns_tsigkey_t *source, dns_tsigkey_t **targetp) { static void tsigkey_free(dns_tsigkey_t *key) { - REQUIRE(VALID_TSIG_KEY(key)); - - key->magic = 0; dns_name_free(&key->name); if (algname_is_allocated(key->algorithm)) { dns_name_free(key->algorithm); @@ -407,7 +398,6 @@ dns_tsigkey_detach(dns_tsigkey_t **keyp) { unsigned int refs; REQUIRE(keyp != NULL); - REQUIRE(VALID_TSIG_KEY(*keyp)); key = *keyp; isc_refcount_decrement(&key->refs, &refs); @@ -439,7 +429,6 @@ dns_tsig_sign(dns_message_t *msg) { REQUIRE(msg != NULL); key = dns_message_gettsigkey(msg); - REQUIRE(VALID_TSIG_KEY(key)); /* * If this is a response, there should be a query tsig. @@ -736,12 +725,9 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg) isc_boolean_t response; REQUIRE(source != NULL); - REQUIRE(DNS_MESSAGE_VALID(msg)); tsigkey = dns_message_gettsigkey(msg); response = is_response(msg); - REQUIRE(tsigkey == NULL || VALID_TSIG_KEY(tsigkey)); - msg->verify_attempted = 1; msg->verified_sig = 0; msg->tsigstatus = dns_tsigerror_badsig; diff --git a/usr.bin/dig/lib/isc/app_api.c b/usr.bin/dig/lib/isc/app_api.c deleted file mode 100644 index 3a366b25151..00000000000 --- a/usr.bin/dig/lib/isc/app_api.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: app_api.c,v 1.2 2020/02/17 18:58:39 jung Exp $ */ - - - -#include <unistd.h> - -#include <isc/app.h> -#include <isc/magic.h> -#include <isc/util.h> - -static isc_appctxcreatefunc_t appctx_createfunc = NULL; -static isc_boolean_t is_running = ISC_FALSE; - -#define ISCAPI_APPMETHODS_VALID(m) ISC_MAGIC_VALID(m, ISCAPI_APPMETHODS_MAGIC) - -isc_result_t -isc_app_start(void) { - return (isc__app_start()); -} - -isc_result_t -isc_app_onrun(isc_task_t *task, - isc_taskaction_t action, void *arg) -{ - return (isc__app_onrun(task, action, arg)); -} - -isc_result_t -isc_app_run() { - isc_result_t result; - - is_running = ISC_TRUE; - result = isc__app_run(); - is_running = ISC_FALSE; - return (result); -} - -isc_boolean_t -isc_app_isrunning() { - return (is_running); -} - -isc_result_t -isc_app_shutdown(void) { - return (isc__app_shutdown()); -} - -void -isc_app_finish(void) { - isc__app_finish(); -} - -void -isc_app_block(void) { - isc__app_block(); -} - -void -isc_app_unblock(void) { - isc__app_unblock(); -} diff --git a/usr.bin/dig/lib/isc/buffer.c b/usr.bin/dig/lib/isc/buffer.c index 9e4a8ee732c..5a5bd276775 100644 --- a/usr.bin/dig/lib/isc/buffer.c +++ b/usr.bin/dig/lib/isc/buffer.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: buffer.c,v 1.2 2020/02/12 13:05:04 jsg Exp $ */ +/* $Id: buffer.c,v 1.3 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -54,7 +54,6 @@ isc__buffer_invalidate(isc_buffer_t *b) { * Make 'b' an invalid buffer. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(!ISC_LINK_LINKED(b, link)); ISC__BUFFER_INVALIDATE(b); @@ -66,7 +65,6 @@ isc__buffer_region(isc_buffer_t *b, isc_region_t *r) { * Make 'r' refer to the region of 'b'. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(r != NULL); ISC__BUFFER_REGION(b, r); @@ -78,7 +76,6 @@ isc__buffer_usedregion(isc_buffer_t *b, isc_region_t *r) { * Make 'r' refer to the used region of 'b'. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(r != NULL); ISC__BUFFER_USEDREGION(b, r); @@ -90,7 +87,6 @@ isc__buffer_availableregion(isc_buffer_t *b, isc_region_t *r) { * Make 'r' refer to the available region of 'b'. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(r != NULL); ISC__BUFFER_AVAILABLEREGION(b, r); @@ -102,7 +98,6 @@ isc__buffer_add(isc_buffer_t *b, unsigned int n) { * Increase the 'used' region of 'b' by 'n' bytes. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used + n <= b->length); ISC__BUFFER_ADD(b, n); @@ -114,7 +109,6 @@ isc__buffer_subtract(isc_buffer_t *b, unsigned int n) { * Decrease the 'used' region of 'b' by 'n' bytes. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used >= n); ISC__BUFFER_SUBTRACT(b, n); @@ -126,8 +120,6 @@ isc__buffer_clear(isc_buffer_t *b) { * Make the used region empty. */ - REQUIRE(ISC_BUFFER_VALID(b)); - ISC__BUFFER_CLEAR(b); } @@ -137,7 +129,6 @@ isc__buffer_consumedregion(isc_buffer_t *b, isc_region_t *r) { * Make 'r' refer to the consumed region of 'b'. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(r != NULL); ISC__BUFFER_CONSUMEDREGION(b, r); @@ -149,7 +140,6 @@ isc__buffer_remainingregion(isc_buffer_t *b, isc_region_t *r) { * Make 'r' refer to the remaining region of 'b'. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(r != NULL); ISC__BUFFER_REMAININGREGION(b, r); @@ -161,7 +151,6 @@ isc__buffer_activeregion(isc_buffer_t *b, isc_region_t *r) { * Make 'r' refer to the active region of 'b'. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(r != NULL); ISC__BUFFER_ACTIVEREGION(b, r); @@ -173,7 +162,6 @@ isc__buffer_setactive(isc_buffer_t *b, unsigned int n) { * Sets the end of the active region 'n' bytes after current. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->current + n <= b->used); ISC__BUFFER_SETACTIVE(b, n); @@ -185,8 +173,6 @@ isc__buffer_first(isc_buffer_t *b) { * Make the consumed region empty. */ - REQUIRE(ISC_BUFFER_VALID(b)); - ISC__BUFFER_FIRST(b); } @@ -196,7 +182,6 @@ isc__buffer_forward(isc_buffer_t *b, unsigned int n) { * Increase the 'consumed' region of 'b' by 'n' bytes. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->current + n <= b->used); ISC__BUFFER_FORWARD(b, n); @@ -208,7 +193,6 @@ isc__buffer_back(isc_buffer_t *b, unsigned int n) { * Decrease the 'consumed' region of 'b' by 'n' bytes. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(n <= b->current); ISC__BUFFER_BACK(b, n); @@ -225,8 +209,6 @@ isc_buffer_compact(isc_buffer_t *b) { * of the consumed region, and the consumed region is then made empty. */ - REQUIRE(ISC_BUFFER_VALID(b)); - src = isc_buffer_current(b); length = isc_buffer_remaininglength(b); (void)memmove(b->base, src, (size_t)length); @@ -248,7 +230,6 @@ isc_buffer_getuint8(isc_buffer_t *b) { * Read an unsigned 8-bit integer from 'b' and return it. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used - b->current >= 1); cp = isc_buffer_current(b); @@ -260,7 +241,6 @@ isc_buffer_getuint8(isc_buffer_t *b) { void isc__buffer_putuint8(isc_buffer_t *b, uint8_t val) { - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used + 1 <= b->length); ISC__BUFFER_PUTUINT8(b, val); @@ -276,7 +256,6 @@ isc_buffer_getuint16(isc_buffer_t *b) { * convert it to host byte order, and return it. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used - b->current >= 2); cp = isc_buffer_current(b); @@ -289,7 +268,6 @@ isc_buffer_getuint16(isc_buffer_t *b) { void isc__buffer_putuint16(isc_buffer_t *b, uint16_t val) { - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used + 2 <= b->length); ISC__BUFFER_PUTUINT16(b, val); @@ -297,7 +275,6 @@ isc__buffer_putuint16(isc_buffer_t *b, uint16_t val) { void isc__buffer_putuint24(isc_buffer_t *b, uint32_t val) { - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used + 3 <= b->length); ISC__BUFFER_PUTUINT24(b, val); @@ -313,7 +290,6 @@ isc_buffer_getuint32(isc_buffer_t *b) { * convert it to host byte order, and return it. */ - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used - b->current >= 4); cp = isc_buffer_current(b); @@ -328,7 +304,6 @@ isc_buffer_getuint32(isc_buffer_t *b) { void isc__buffer_putuint32(isc_buffer_t *b, uint32_t val) { - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used + 4 <= b->length); ISC__BUFFER_PUTUINT32(b, val); @@ -339,7 +314,6 @@ isc__buffer_putuint48(isc_buffer_t *b, uint64_t val) { uint16_t valhi; uint32_t vallo; - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used + 6 <= b->length); valhi = (uint16_t)(val >> 32); @@ -352,7 +326,6 @@ void isc__buffer_putmem(isc_buffer_t *b, const unsigned char *base, unsigned int length) { - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(b->used + length <= b->length); ISC__BUFFER_PUTMEM(b, base, length); @@ -363,7 +336,6 @@ isc__buffer_putstr(isc_buffer_t *b, const char *source) { unsigned int l; unsigned char *cp; - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(source != NULL); /* @@ -383,7 +355,6 @@ isc_buffer_copyregion(isc_buffer_t *b, const isc_region_t *r) { unsigned char *base; unsigned int available; - REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(r != NULL); /* @@ -415,8 +386,6 @@ isc_buffer_allocate(isc_buffer_t **dynbuffer, isc_buffer_init(dbuf, ((unsigned char *)dbuf) + sizeof(isc_buffer_t), length); - ENSURE(ISC_BUFFER_VALID(dbuf)); - *dynbuffer = dbuf; return (ISC_R_SUCCESS); @@ -428,8 +397,6 @@ isc_buffer_free(isc_buffer_t **dynbuffer) { isc_buffer_t *dbuf; REQUIRE(dynbuffer != NULL); - REQUIRE(ISC_BUFFER_VALID(*dynbuffer)); - dbuf = *dynbuffer; *dynbuffer = NULL; /* destroy external reference */ diff --git a/usr.bin/dig/lib/isc/bufferlist.c b/usr.bin/dig/lib/isc/bufferlist.c index 22dd18937a4..33e428efe37 100644 --- a/usr.bin/dig/lib/isc/bufferlist.c +++ b/usr.bin/dig/lib/isc/bufferlist.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: bufferlist.c,v 1.1 2020/02/07 09:58:53 florian Exp $ */ +/* $Id: bufferlist.c,v 1.2 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -36,7 +36,6 @@ isc_bufferlist_usedcount(isc_bufferlist_t *bl) { length = 0; buffer = ISC_LIST_HEAD(*bl); while (buffer != NULL) { - REQUIRE(ISC_BUFFER_VALID(buffer)); length += isc_buffer_usedlength(buffer); buffer = ISC_LIST_NEXT(buffer, link); } @@ -54,7 +53,6 @@ isc_bufferlist_availablecount(isc_bufferlist_t *bl) { length = 0; buffer = ISC_LIST_HEAD(*bl); while (buffer != NULL) { - REQUIRE(ISC_BUFFER_VALID(buffer)); length += isc_buffer_availablelength(buffer); buffer = ISC_LIST_NEXT(buffer, link); } diff --git a/usr.bin/dig/lib/isc/hash.c b/usr.bin/dig/lib/isc/hash.c index 8e848f08ca6..befa9110003 100644 --- a/usr.bin/dig/lib/isc/hash.c +++ b/usr.bin/dig/lib/isc/hash.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: hash.c,v 1.2 2020/02/17 18:58:39 jung Exp $ */ +/* $Id: hash.c,v 1.3 2020/02/18 18:11:27 florian Exp $ */ /*! \file * Some portion of this code was derived from universal hash function @@ -59,14 +59,10 @@ if advised of the possibility of such damage. #include <stdlib.h> #include <isc/hash.h> -#include <isc/magic.h> #include <isc/refcount.h> #include <string.h> #include <isc/util.h> -#define HASH_MAGIC ISC_MAGIC('H', 'a', 's', 'h') -#define VALID_HASH(h) ISC_MAGIC_VALID((h), HASH_MAGIC) - /*% * A large 32-bit prime number that specifies the range of the hash output. */ @@ -83,7 +79,6 @@ typedef uint16_t hash_random_t; /*% isc hash structure */ struct isc_hash { - unsigned int magic; isc_boolean_t initialized; isc_refcount_t refcnt; size_t limit; /*%< upper limit of key length */ diff --git a/usr.bin/dig/lib/isc/heap.c b/usr.bin/dig/lib/isc/heap.c index 98d240bd0a1..53326533eae 100644 --- a/usr.bin/dig/lib/isc/heap.c +++ b/usr.bin/dig/lib/isc/heap.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: heap.c,v 1.3 2020/02/13 08:18:44 florian Exp $ */ +/* $Id: heap.c,v 1.4 2020/02/18 18:11:27 florian Exp $ */ /*! \file * Heap implementation of priority queues adapted from the following: @@ -29,7 +29,6 @@ #include <stdlib.h> #include <isc/heap.h> -#include <isc/magic.h> #include <string.h> #include <isc/util.h> @@ -46,9 +45,6 @@ #define SIZE_INCREMENT 1024 -#define HEAP_MAGIC ISC_MAGIC('H', 'E', 'A', 'P') -#define VALID_HEAP(h) ISC_MAGIC_VALID(h, HEAP_MAGIC) - /*% * When the heap is in a consistent state, the following invariant * holds true: for every element i > 1, heap_parent(i) has a priority @@ -60,7 +56,6 @@ /*% ISC heap structure. */ struct isc_heap { - unsigned int magic; unsigned int size; unsigned int size_increment; unsigned int last; @@ -82,7 +77,6 @@ isc_heap_create(isc_heapcompare_t compare, heap = malloc(sizeof(*heap)); if (heap == NULL) return (ISC_R_NOMEMORY); - heap->magic = HEAP_MAGIC; heap->size = 0; if (size_increment == 0) heap->size_increment = SIZE_INCREMENT; @@ -104,10 +98,8 @@ isc_heap_destroy(isc_heap_t **heapp) { REQUIRE(heapp != NULL); heap = *heapp; - REQUIRE(VALID_HEAP(heap)); free(heap->array); - heap->magic = 0; free(heap); *heapp = NULL; @@ -118,7 +110,6 @@ resize(isc_heap_t *heap) { void **new_array; unsigned int new_size; - REQUIRE(VALID_HEAP(heap)); new_size = heap->size + heap->size_increment; new_array = malloc(new_size * sizeof(void *)); @@ -181,7 +172,6 @@ isc_result_t isc_heap_insert(isc_heap_t *heap, void *elt) { unsigned int new_last; - REQUIRE(VALID_HEAP(heap)); new_last = heap->last + 1; RUNTIME_CHECK(new_last > 0); /* overflow check */ @@ -199,7 +189,6 @@ isc_heap_delete(isc_heap_t *heap, unsigned int idx) { void *elt; isc_boolean_t less; - REQUIRE(VALID_HEAP(heap)); REQUIRE(idx >= 1 && idx <= heap->last); if (heap->index != NULL) @@ -223,7 +212,6 @@ isc_heap_delete(isc_heap_t *heap, unsigned int idx) { void isc_heap_increased(isc_heap_t *heap, unsigned int idx) { - REQUIRE(VALID_HEAP(heap)); REQUIRE(idx >= 1 && idx <= heap->last); float_up(heap, idx, heap->array[idx]); @@ -231,7 +219,6 @@ isc_heap_increased(isc_heap_t *heap, unsigned int idx) { void isc_heap_decreased(isc_heap_t *heap, unsigned int idx) { - REQUIRE(VALID_HEAP(heap)); REQUIRE(idx >= 1 && idx <= heap->last); sink_down(heap, idx, heap->array[idx]); @@ -239,7 +226,6 @@ isc_heap_decreased(isc_heap_t *heap, unsigned int idx) { void * isc_heap_element(isc_heap_t *heap, unsigned int idx) { - REQUIRE(VALID_HEAP(heap)); REQUIRE(idx >= 1); if (idx <= heap->last) diff --git a/usr.bin/dig/lib/isc/include/isc/app.h b/usr.bin/dig/lib/isc/include/isc/app.h index e371d54b59d..d403b5c0ea3 100644 --- a/usr.bin/dig/lib/isc/include/isc/app.h +++ b/usr.bin/dig/lib/isc/include/isc/app.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: app.h,v 1.4 2020/02/18 18:10:17 florian Exp $ */ +/* $Id: app.h,v 1.5 2020/02/18 18:11:27 florian Exp $ */ #ifndef ISC_APP_H #define ISC_APP_H 1 @@ -77,7 +77,6 @@ */ #include <isc/eventclass.h> -#include <isc/magic.h> #include <isc/result.h> /*** @@ -90,24 +89,6 @@ typedef isc_event_t isc_appevent_t; #define ISC_APPEVENT_SHUTDOWN (ISC_EVENTCLASS_APP + 1) #define ISC_APPEVENT_LASTEVENT (ISC_EVENTCLASS_APP + 65535) -/*% - * This structure is actually just the common prefix of an application context - * implementation's version of an isc_appctx_t. - * \brief - * Direct use of this structure by clients is forbidden. app implementations - * may change the structure. 'magic' must be ISCAPI_APPCTX_MAGIC for any - * of the isc_app_ routines to work. app implementations must maintain - * all app context invariants. - */ -struct isc_appctx { - unsigned int impmagic; - unsigned int magic; -}; - -#define ISCAPI_APPCTX_MAGIC ISC_MAGIC('A','a','p','c') -#define ISCAPI_APPCTX_VALID(c) ((c) != NULL && \ - (c)->magic == ISCAPI_APPCTX_MAGIC) - isc_result_t isc_app_start(void); /*!< @@ -188,22 +169,6 @@ isc_app_shutdown(void); */ void -isc_app_finish(void); -/*!< - * \brief Finish an ISC library application. - * - * Notes: - *\li This call should be made at or near the end of main(). - * - * Requires: - *\li isc_app_start() has been called. - *\li 'ctx' is a valid application context (for app_ctxfinish()). - * - * Ensures: - *\li Any resources allocated by isc_app_start() have been released. - */ - -void isc_app_block(void); /*!< * \brief Indicate that a blocking operation will be performed. diff --git a/usr.bin/dig/lib/isc/include/isc/buffer.h b/usr.bin/dig/lib/isc/include/isc/buffer.h index 190a6496b24..acc84999da2 100644 --- a/usr.bin/dig/lib/isc/include/isc/buffer.h +++ b/usr.bin/dig/lib/isc/include/isc/buffer.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: buffer.h,v 1.5 2020/02/15 10:56:25 florian Exp $ */ +/* $Id: buffer.h,v 1.6 2020/02/18 18:11:27 florian Exp $ */ #ifndef ISC_BUFFER_H #define ISC_BUFFER_H 1 @@ -108,8 +108,6 @@ #include <inttypes.h> - -#include <isc/magic.h> #include <isc/types.h> /*! @@ -118,14 +116,6 @@ */ /* #define ISC_BUFFER_USEINLINE */ -/*@{*/ -/*! - *** Magic numbers - ***/ -#define ISC_BUFFER_MAGIC 0x42756621U /* Buf!. */ -#define ISC_BUFFER_VALID(b) ISC_MAGIC_VALID(b, ISC_BUFFER_MAGIC) -/*@}*/ - /* * The following macros MUST be used only on valid buffers. It is the * caller's responsibility to ensure this by using the ISC_BUFFER_VALID @@ -165,7 +155,6 @@ */ struct isc_buffer { - unsigned int magic; void *base; /*@{*/ /*! The following integers are byte offsets from 'base'. */ @@ -648,14 +637,12 @@ isc_buffer_copyregion(isc_buffer_t *b, const isc_region_t *r); (_b)->current = 0; \ (_b)->active = 0; \ ISC_LINK_INIT(_b, link); \ - (_b)->magic = ISC_BUFFER_MAGIC; \ } while (0) #define ISC__BUFFER_INITNULL(_b) ISC__BUFFER_INIT(_b, NULL, 0) #define ISC__BUFFER_INVALIDATE(_b) \ do { \ - (_b)->magic = 0; \ (_b)->base = NULL; \ (_b)->length = 0; \ (_b)->used = 0; \ diff --git a/usr.bin/dig/lib/isc/include/isc/magic.h b/usr.bin/dig/lib/isc/include/isc/magic.h deleted file mode 100644 index 02d1bd595ad..00000000000 --- a/usr.bin/dig/lib/isc/include/isc/magic.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: magic.h,v 1.1 2020/02/07 09:58:54 florian Exp $ */ - -#ifndef ISC_MAGIC_H -#define ISC_MAGIC_H 1 - - - -/*! \file isc/magic.h */ - -typedef struct { - unsigned int magic; -} isc__magic_t; - - -/*% - * To use this macro the magic number MUST be the first thing in the - * structure, and MUST be of type "unsigned int". - * The intent of this is to allow magic numbers to be checked even though - * the object is otherwise opaque. - */ -#define ISC_MAGIC_VALID(a,b) (((a) != NULL) && \ - (((const isc__magic_t *)(a))->magic == (b))) - -#define ISC_MAGIC(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d)) - -#endif /* ISC_MAGIC_H */ diff --git a/usr.bin/dig/lib/isc/include/isc/socket.h b/usr.bin/dig/lib/isc/include/isc/socket.h index 23de1086474..3f15155163a 100644 --- a/usr.bin/dig/lib/isc/include/isc/socket.h +++ b/usr.bin/dig/lib/isc/include/isc/socket.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.h,v 1.4 2020/02/18 18:10:17 florian Exp $ */ +/* $Id: socket.h,v 1.5 2020/02/18 18:11:27 florian Exp $ */ #ifndef ISC_SOCKET_H #define ISC_SOCKET_H 1 @@ -190,41 +190,6 @@ typedef enum { #define ISC_SOCKFDWATCH_WRITE 0x00000002 /*%< watch for writable */ /*@}*/ -/*% - * This structure is actually just the common prefix of a socket manager - * object implementation's version of an isc_socketmgr_t. - * \brief - * Direct use of this structure by clients is forbidden. socket implementations - * may change the structure. 'magic' must be ISCAPI_SOCKETMGR_MAGIC for any - * of the isc_socket_ routines to work. socket implementations must maintain - * all socket invariants. - * In effect, this definition is used only for non-BIND9 version ("export") - * of the library, and the export version does not work for win32. So, to avoid - * the definition conflict with win32/socket.c, we enable this definition only - * for non-Win32 (i.e. Unix) platforms. - */ -struct isc_socketmgr { - unsigned int impmagic; - unsigned int magic; -}; - -#define ISCAPI_SOCKETMGR_MAGIC ISC_MAGIC('A','s','m','g') -#define ISCAPI_SOCKETMGR_VALID(m) ((m) != NULL && \ - (m)->magic == ISCAPI_SOCKETMGR_MAGIC) - -/*% - * This is the common prefix of a socket object. The same note as - * that for the socketmgr structure applies. - */ -struct isc_socket { - unsigned int impmagic; - unsigned int magic; -}; - -#define ISCAPI_SOCKET_MAGIC ISC_MAGIC('A','s','c','t') -#define ISCAPI_SOCKET_VALID(s) ((s) != NULL && \ - (s)->magic == ISCAPI_SOCKET_MAGIC) - /*** *** Socket and Socket Manager Functions *** diff --git a/usr.bin/dig/lib/isc/include/isc/task.h b/usr.bin/dig/lib/isc/include/isc/task.h index d493d182d79..887f0f1183d 100644 --- a/usr.bin/dig/lib/isc/include/isc/task.h +++ b/usr.bin/dig/lib/isc/include/isc/task.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: task.h,v 1.5 2020/02/18 18:10:17 florian Exp $ */ +/* $Id: task.h,v 1.6 2020/02/18 18:11:27 florian Exp $ */ #ifndef ISC_TASK_H #define ISC_TASK_H 1 @@ -100,37 +100,6 @@ typedef enum { isc_taskmgrmode_privileged } isc_taskmgrmode_t; -/*% - * This structure is actually just the common prefix of a task manager - * object implementation's version of an isc_taskmgr_t. - * \brief - * Direct use of this structure by clients is forbidden. task implementations - * may change the structure. 'magic' must be ISCAPI_TASKMGR_MAGIC for any - * of the isc_task_ routines to work. task implementations must maintain - * all task invariants. - */ -struct isc_taskmgr { - unsigned int impmagic; - unsigned int magic; -}; - -#define ISCAPI_TASKMGR_MAGIC ISC_MAGIC('A','t','m','g') -#define ISCAPI_TASKMGR_VALID(m) ((m) != NULL && \ - (m)->magic == ISCAPI_TASKMGR_MAGIC) - -/*% - * This is the common prefix of a task object. The same note as - * that for the taskmgr structure applies. - */ -struct isc_task { - unsigned int impmagic; - unsigned int magic; -}; - -#define ISCAPI_TASK_MAGIC ISC_MAGIC('A','t','s','t') -#define ISCAPI_TASK_VALID(s) ((s) != NULL && \ - (s)->magic == ISCAPI_TASK_MAGIC) - isc_result_t isc_task_create(isc_taskmgr_t *manager, unsigned int quantum, isc_task_t **taskp); diff --git a/usr.bin/dig/lib/isc/include/isc/timer.h b/usr.bin/dig/lib/isc/include/isc/timer.h index 1dc618598e1..6eb76fa61a3 100644 --- a/usr.bin/dig/lib/isc/include/isc/timer.h +++ b/usr.bin/dig/lib/isc/include/isc/timer.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: timer.h,v 1.9 2020/02/16 21:08:59 florian Exp $ */ +/* $Id: timer.h,v 1.10 2020/02/18 18:11:27 florian Exp $ */ #ifndef ISC_TIMER_H #define ISC_TIMER_H 1 @@ -93,37 +93,6 @@ typedef struct isc_timerevent { #define ISC_TIMEREVENT_LIFE (ISC_EVENTCLASS_TIMER + 3) #define ISC_TIMEREVENT_LASTEVENT (ISC_EVENTCLASS_TIMER + 65535) -/*% - * This structure is actually just the common prefix of a timer manager - * object implementation's version of an isc_timermgr_t. - * \brief - * Direct use of this structure by clients is forbidden. timer implementations - * may change the structure. 'magic' must be ISCAPI_TIMERMGR_MAGIC for any - * of the isc_timer_ routines to work. timer implementations must maintain - * all timer invariants. - */ -struct isc_timermgr { - unsigned int impmagic; - unsigned int magic; -}; - -#define ISCAPI_TIMERMGR_MAGIC ISC_MAGIC('A','t','m','g') -#define ISCAPI_TIMERMGR_VALID(m) ((m) != NULL && \ - (m)->magic == ISCAPI_TIMERMGR_MAGIC) - -/*% - * This is the common prefix of a timer object. The same note as - * that for the timermgr structure applies. - */ -struct isc_timer { - unsigned int impmagic; - unsigned int magic; -}; - -#define ISCAPI_TIMER_MAGIC ISC_MAGIC('A','t','m','r') -#define ISCAPI_TIMER_VALID(s) ((s) != NULL && \ - (s)->magic == ISCAPI_TIMER_MAGIC) - /*** *** Timer and Timer Manager Functions *** diff --git a/usr.bin/dig/lib/isc/lex.c b/usr.bin/dig/lib/isc/lex.c index 439eef3beac..22aaaad37d8 100644 --- a/usr.bin/dig/lib/isc/lex.c +++ b/usr.bin/dig/lib/isc/lex.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: lex.c,v 1.4 2020/02/17 19:45:00 jung Exp $ */ +/* $Id: lex.c,v 1.5 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -50,12 +50,8 @@ typedef struct inputsource { ISC_LINK(struct inputsource) link; } inputsource; -#define LEX_MAGIC ISC_MAGIC('L', 'e', 'x', '!') -#define VALID_LEX(l) ISC_MAGIC_VALID(l, LEX_MAGIC) - struct isc_lex { /* Unlocked. */ - unsigned int magic; size_t max_token; char * data; unsigned int comments; @@ -113,7 +109,6 @@ isc_lex_create(size_t max_token, isc_lex_t **lexp) { lex->saved_paren_count = 0; memset(lex->specials, 0, 256); INIT_LIST(lex->sources); - lex->magic = LEX_MAGIC; *lexp = lex; @@ -130,13 +125,11 @@ isc_lex_destroy(isc_lex_t **lexp) { REQUIRE(lexp != NULL); lex = *lexp; - REQUIRE(VALID_LEX(lex)); while (!EMPTY(lex->sources)) RUNTIME_CHECK(isc_lex_close(lex) == ISC_R_SUCCESS); if (lex->data != NULL) free(lex->data); - lex->magic = 0; free(lex); *lexp = NULL; @@ -148,7 +141,6 @@ isc_lex_setcomments(isc_lex_t *lex, unsigned int comments) { * Set allowed lexer commenting styles. */ - REQUIRE(VALID_LEX(lex)); lex->comments = comments; } @@ -160,7 +152,6 @@ isc_lex_setspecials(isc_lex_t *lex, isc_lexspecials_t specials) { * whitespace, they delimit strings and numbers. */ - REQUIRE(VALID_LEX(lex)); memmove(lex->specials, specials, 256); } @@ -210,7 +201,6 @@ isc_lex_openfile(isc_lex_t *lex, const char *filename) { * Open 'filename' and make it the current input source for 'lex'. */ - REQUIRE(VALID_LEX(lex)); if ((stream = fopen(filename, "r")) == NULL) return (isc__errno2result(errno)); @@ -229,7 +219,6 @@ isc_lex_close(isc_lex_t *lex) { * Close the most recently opened object (i.e. file or buffer). */ - REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); if (source == NULL) @@ -318,7 +307,6 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { * Get the next token. */ - REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); REQUIRE(tokenp != NULL); @@ -802,7 +790,6 @@ isc_lex_ungettoken(isc_lex_t *lex, isc_token_t *tokenp) { * Unget the current token. */ - REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); REQUIRE(source != NULL); REQUIRE(tokenp != NULL); @@ -822,7 +809,6 @@ isc_lex_getlasttokentext(isc_lex_t *lex, isc_token_t *tokenp, isc_region_t *r) { inputsource *source; - REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); REQUIRE(source != NULL); REQUIRE(tokenp != NULL); @@ -843,7 +829,6 @@ char * isc_lex_getsourcename(isc_lex_t *lex) { inputsource *source; - REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); if (source == NULL) @@ -856,7 +841,6 @@ unsigned long isc_lex_getsourceline(isc_lex_t *lex) { inputsource *source; - REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); if (source == NULL) @@ -869,8 +853,6 @@ isc_boolean_t isc_lex_isfile(isc_lex_t *lex) { inputsource *source; - REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); if (source == NULL) diff --git a/usr.bin/dig/lib/isc/log.c b/usr.bin/dig/lib/isc/log.c index 820a3e9ad3d..857c1f69a3a 100644 --- a/usr.bin/dig/lib/isc/log.c +++ b/usr.bin/dig/lib/isc/log.c @@ -14,28 +14,20 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: log.c,v 1.14 2020/02/17 18:58:39 jung Exp $ */ +/* $Id: log.c,v 1.15 2020/02/18 18:11:27 florian Exp $ */ /*! \file * \author Principal Authors: DCL */ - -#include <stdlib.h> #include <limits.h> +#include <stdlib.h> +#include <string.h> #include <syslog.h> #include <isc/log.h> -#include <isc/magic.h> -#include <string.h> #include <isc/time.h> #include <isc/util.h> -#define LCTX_MAGIC ISC_MAGIC('L', 'c', 't', 'x') -#define VALID_CONTEXT(lctx) ISC_MAGIC_VALID(lctx, LCTX_MAGIC) - -#define LCFG_MAGIC ISC_MAGIC('L', 'c', 'f', 'g') -#define VALID_CONFIG(lcfg) ISC_MAGIC_VALID(lcfg, LCFG_MAGIC) - /* * XXXDCL make dynamic? */ @@ -97,7 +89,6 @@ struct isc_logmessage { * into a program, or the debug_level which is dynamic state information. */ struct isc_logconfig { - unsigned int magic; isc_log_t * lctx; ISC_LIST(isc_logchannel_t) channels; ISC_LIST(isc_logchannellist_t) *channellists; @@ -127,7 +118,6 @@ struct isc_logconfig { */ struct isc_log { /* Not locked. */ - unsigned int magic; isc_logcategory_t * categories; unsigned int category_count; isc_logmodule_t * modules; @@ -257,15 +247,6 @@ isc_log_create(isc_log_t **lctxp, isc_logconfig_t **lcfgp) { ISC_LIST_INIT(lctx->messages); - /* - * Normally setting the magic number is the last step done - * in a creation function, but a valid log context is needed - * by isc_log_registercategories and isc_logconfig_create. - * If either fails, the lctx is destroyed and not returned - * to the caller. - */ - lctx->magic = LCTX_MAGIC; - isc_log_registercategories(lctx, isc_categories); isc_log_registermodules(lctx, isc_modules); result = isc_logconfig_create(lctx, &lcfg); @@ -301,7 +282,6 @@ isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) { int level = ISC_LOG_INFO; REQUIRE(lcfgp != NULL && *lcfgp == NULL); - REQUIRE(VALID_CONTEXT(lctx)); lcfg = malloc(sizeof(*lcfg)); @@ -316,14 +296,6 @@ isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) { ISC_LIST_INIT(lcfg->channels); - /* - * Normally the magic number is the last thing set in the - * structure, but isc_log_createchannel() needs a valid - * config. If the channel creation fails, the lcfg is not - * returned to the caller. - */ - lcfg->magic = LCFG_MAGIC; - } else result = ISC_R_NOMEMORY; @@ -391,7 +363,7 @@ isc_log_destroy(isc_log_t **lctxp) { isc_logconfig_t *lcfg; isc_logmessage_t *message; - REQUIRE(lctxp != NULL && VALID_CONTEXT(*lctxp)); + REQUIRE(lctxp != NULL); lctx = *lctxp; if (lctx->logconfig != NULL) { @@ -412,10 +384,7 @@ isc_log_destroy(isc_log_t **lctxp) { lctx->category_count = 0; lctx->modules = NULL; lctx->module_count = 0; - lctx->magic = 0; - free(lctx); - *lctxp = NULL; } @@ -426,7 +395,7 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) { isc_logchannellist_t *item; unsigned int i; - REQUIRE(lcfgp != NULL && VALID_CONFIG(*lcfgp)); + REQUIRE(lcfgp != NULL); lcfg = *lcfgp; @@ -458,10 +427,7 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) { lcfg->tag = NULL; lcfg->highest_level = 0; lcfg->duplicate_interval = 0; - lcfg->magic = 0; - free(lcfg); - *lcfgp = NULL; } @@ -469,7 +435,6 @@ void isc_log_registercategories(isc_log_t *lctx, isc_logcategory_t categories[]) { isc_logcategory_t *catp; - REQUIRE(VALID_CONTEXT(lctx)); REQUIRE(categories != NULL && categories[0].name != NULL); /* @@ -513,7 +478,6 @@ void isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]) { isc_logmodule_t *modp; - REQUIRE(VALID_CONTEXT(lctx)); REQUIRE(modules != NULL && modules[0].name != NULL); /* @@ -561,7 +525,6 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name, { isc_logchannel_t *channel; - REQUIRE(VALID_CONFIG(lcfg)); REQUIRE(name != NULL); REQUIRE(type == ISC_LOG_TOSYSLOG || type == ISC_LOG_TOFILEDESC || type == ISC_LOG_TONULL); @@ -631,7 +594,6 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name, isc_result_t result = ISC_R_SUCCESS; unsigned int i; - REQUIRE(VALID_CONFIG(lcfg)); REQUIRE(name != NULL); lctx = lcfg->lctx; @@ -686,7 +648,6 @@ isc_log_setcontext(isc_log_t *lctx) { void isc_log_setdebuglevel(isc_log_t *lctx, unsigned int level) { - REQUIRE(VALID_CONTEXT(lctx)); lctx->debug_level = level; } @@ -703,8 +664,6 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id, isc_log_t *lctx; isc_result_t result; - REQUIRE(VALID_CONFIG(lcfg)); - lctx = lcfg->lctx; REQUIRE(category_id < lctx->category_count); @@ -752,8 +711,6 @@ sync_channellist(isc_logconfig_t *lcfg) { isc_log_t *lctx; void *lists; - REQUIRE(VALID_CONFIG(lcfg)); - lctx = lcfg->lctx; REQUIRE(lctx->category_count != 0); @@ -822,7 +779,6 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, isc_logchannel_t *channel; isc_logchannellist_t *category_channels; - REQUIRE(lctx == NULL || VALID_CONTEXT(lctx)); REQUIRE(category != NULL); REQUIRE(module != NULL); REQUIRE(level != ISC_LOG_DYNAMIC); diff --git a/usr.bin/dig/lib/isc/socket_api.c b/usr.bin/dig/lib/isc/socket_api.c deleted file mode 100644 index 92d40346fd2..00000000000 --- a/usr.bin/dig/lib/isc/socket_api.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: socket_api.c,v 1.1 2020/02/07 09:58:54 florian Exp $ */ - - - -#include <isc/app.h> -#include <isc/magic.h> -#include <isc/socket.h> -#include <isc/util.h> - -isc_result_t -isc_socketmgr_create(isc_socketmgr_t **managerp) { - return (isc__socketmgr_create(managerp)); -} - -void -isc_socketmgr_destroy(isc_socketmgr_t **managerp) { - REQUIRE(managerp != NULL && ISCAPI_SOCKETMGR_VALID(*managerp)); - - isc__socketmgr_destroy(managerp); - - ENSURE(*managerp == NULL); -} - -isc_result_t -isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, - isc_socket_t **socketp) -{ - REQUIRE(ISCAPI_SOCKETMGR_VALID(manager)); - - return (isc__socket_create(manager, pf, type, socketp)); -} - -void -isc_socket_attach(isc_socket_t *sock, isc_socket_t **socketp) { - REQUIRE(ISCAPI_SOCKET_VALID(sock)); - REQUIRE(socketp != NULL && *socketp == NULL); - - isc__socket_attach(sock, socketp); - - ENSURE(*socketp == sock); -} - -void -isc_socket_detach(isc_socket_t **socketp) { - REQUIRE(socketp != NULL && ISCAPI_SOCKET_VALID(*socketp)); - - isc__socket_detach(socketp); - - ENSURE(*socketp == NULL); -} - -isc_result_t -isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr, - unsigned int options) -{ - REQUIRE(ISCAPI_SOCKET_VALID(sock)); - - return (isc__socket_bind(sock, sockaddr, options)); -} - -isc_result_t -isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr, isc_task_t *task, - isc_taskaction_t action, void *arg) -{ - REQUIRE(ISCAPI_SOCKET_VALID(sock)); - - return (isc__socket_connect(sock, addr, task, action, arg)); -} - -void -isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) { - REQUIRE(ISCAPI_SOCKET_VALID(sock)); - - isc__socket_cancel(sock, task, how); -} - -isc_result_t -isc_socket_recvv(isc_socket_t *sock, isc_bufferlist_t *buflist, - unsigned int minimum, isc_task_t *task, - isc_taskaction_t action, void *arg) -{ - return (isc__socket_recvv(sock, buflist, minimum, task, action, arg)); -} - -isc_result_t -isc_socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist, - isc_task_t *task, isc_taskaction_t action, void *arg) -{ - return (isc__socket_sendv(sock, buflist, task, action, arg)); -} - -isc_result_t -isc_socket_sendtov2(isc_socket_t *sock, isc_bufferlist_t *buflist, - isc_task_t *task, isc_taskaction_t action, void *arg, - isc_sockaddr_t *address, struct in6_pktinfo *pktinfo, - unsigned int flags) -{ - return (isc__socket_sendtov2(sock, buflist, task, action, arg, - address, pktinfo, flags)); -} diff --git a/usr.bin/dig/lib/isc/symtab.c b/usr.bin/dig/lib/isc/symtab.c index e9392002020..616afff494d 100644 --- a/usr.bin/dig/lib/isc/symtab.c +++ b/usr.bin/dig/lib/isc/symtab.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: symtab.c,v 1.2 2020/02/17 18:58:39 jung Exp $ */ +/* $Id: symtab.c,v 1.3 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ @@ -22,7 +22,6 @@ #include <ctype.h> #include <stdlib.h> -#include <isc/magic.h> #include <string.h> #include <isc/symtab.h> #include <isc/util.h> @@ -36,12 +35,8 @@ typedef struct elt { typedef LIST(elt_t) eltlist_t; -#define SYMTAB_MAGIC ISC_MAGIC('S', 'y', 'm', 'T') -#define VALID_SYMTAB(st) ISC_MAGIC_VALID(st, SYMTAB_MAGIC) - struct isc_symtab { /* Unlocked. */ - unsigned int magic; unsigned int size; unsigned int count; unsigned int maxload; @@ -81,10 +76,7 @@ isc_symtab_create(unsigned int size, symtab->undefine_action = undefine_action; symtab->undefine_arg = undefine_arg; symtab->case_sensitive = case_sensitive; - symtab->magic = SYMTAB_MAGIC; - *symtabp = symtab; - return (ISC_R_SUCCESS); } @@ -96,7 +88,6 @@ isc_symtab_destroy(isc_symtab_t **symtabp) { REQUIRE(symtabp != NULL); symtab = *symtabp; - REQUIRE(VALID_SYMTAB(symtab)); for (i = 0; i < symtab->size; i++) { for (elt = HEAD(symtab->table[i]); elt != NULL; elt = nelt) { @@ -110,9 +101,7 @@ isc_symtab_destroy(isc_symtab_t **symtabp) { } } free(symtab->table); - symtab->magic = 0; free(symtab); - *symtabp = NULL; } @@ -165,7 +154,6 @@ isc_symtab_lookup(isc_symtab_t *symtab, const char *key, unsigned int type, unsigned int bucket; elt_t *elt; - REQUIRE(VALID_SYMTAB(symtab)); REQUIRE(key != NULL); FIND(symtab, key, type, bucket, elt); @@ -225,7 +213,6 @@ isc_symtab_define(isc_symtab_t *symtab, const char *key, unsigned int type, unsigned int bucket; elt_t *elt; - REQUIRE(VALID_SYMTAB(symtab)); REQUIRE(key != NULL); REQUIRE(type != 0); diff --git a/usr.bin/dig/lib/isc/task.c b/usr.bin/dig/lib/isc/task.c index 95ea423d6fc..e9e9ae5c9e1 100644 --- a/usr.bin/dig/lib/isc/task.c +++ b/usr.bin/dig/lib/isc/task.c @@ -28,7 +28,6 @@ #include <time.h> #include <isc/event.h> -#include <isc/magic.h> #include <isc/task.h> #include <isc/util.h> @@ -43,16 +42,12 @@ typedef enum { task_state_done } task_state_t; -#define TASK_MAGIC ISC_MAGIC('T', 'A', 'S', 'K') -#define VALID_TASK(t) ISC_MAGIC_VALID(t, TASK_MAGIC) +typedef struct isc_task isc_task_t; +typedef struct isc_taskmgr isc_taskmgr_t; -typedef struct isc__task isc__task_t; -typedef struct isc__taskmgr isc__taskmgr_t; - -struct isc__task { +struct isc_task { /* Not locked. */ - isc_task_t common; - isc__taskmgr_t * manager; + isc_taskmgr_t * manager; /* Locked by task lock. */ task_state_t state; unsigned int references; @@ -65,9 +60,9 @@ struct isc__task { char name[16]; void * tag; /* Locked by task manager lock. */ - LINK(isc__task_t) link; - LINK(isc__task_t) ready_link; - LINK(isc__task_t) ready_priority_link; + LINK(isc_task_t) link; + LINK(isc_task_t) ready_link; + LINK(isc_task_t) ready_priority_link; }; #define TASK_F_SHUTTINGDOWN 0x01 @@ -76,19 +71,15 @@ struct isc__task { #define TASK_SHUTTINGDOWN(t) (((t)->flags & TASK_F_SHUTTINGDOWN) \ != 0) -#define TASK_MANAGER_MAGIC ISC_MAGIC('T', 'S', 'K', 'M') -#define VALID_MANAGER(m) ISC_MAGIC_VALID(m, TASK_MANAGER_MAGIC) - -typedef ISC_LIST(isc__task_t) isc__tasklist_t; +typedef ISC_LIST(isc_task_t) isc_tasklist_t; -struct isc__taskmgr { +struct isc_taskmgr { /* Not locked. */ - isc_taskmgr_t common; /* Locked by task manager lock. */ unsigned int default_quantum; - LIST(isc__task_t) tasks; - isc__tasklist_t ready_tasks; - isc__tasklist_t ready_priority_tasks; + LIST(isc_task_t) tasks; + isc_tasklist_t ready_tasks; + isc_tasklist_t ready_priority_tasks; isc_taskmgrmode_t mode; unsigned int tasks_running; unsigned int tasks_ready; @@ -101,7 +92,7 @@ struct isc__taskmgr { * to protect the access. We can't use 'lock' since isc_task_detach() * will try to acquire it. */ - isc__task_t *excl; + isc_task_t *excl; unsigned int refs; }; @@ -109,93 +100,26 @@ struct isc__taskmgr { #define DEFAULT_DEFAULT_QUANTUM 5 #define FINISHED(m) ((m)->exiting && EMPTY((m)->tasks)) -static isc__taskmgr_t *taskmgr = NULL; - -/*% - * The following are intended for internal use (indicated by "isc__" - * prefix) but are not declared as static, allowing direct access from - * unit tests etc. - */ - -isc_result_t -isc__task_create(isc_taskmgr_t *manager0, unsigned int quantum, - isc_task_t **taskp); -void -isc__task_attach(isc_task_t *source0, isc_task_t **targetp); -void -isc__task_detach(isc_task_t **taskp); -void -isc__task_send(isc_task_t *task0, isc_event_t **eventp); -void -isc__task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp); -unsigned int -isc__task_purgerange(isc_task_t *task0, void *sender, isc_eventtype_t first, - isc_eventtype_t last, void *tag); -unsigned int -isc__task_purge(isc_task_t *task, void *sender, isc_eventtype_t type, - void *tag); -isc_boolean_t -isc_task_purgeevent(isc_task_t *task0, isc_event_t *event); -unsigned int -isc__task_unsendrange(isc_task_t *task, void *sender, isc_eventtype_t first, - isc_eventtype_t last, void *tag, - isc_eventlist_t *events); -unsigned int -isc__task_unsend(isc_task_t *task, void *sender, isc_eventtype_t type, - void *tag, isc_eventlist_t *events); -isc_result_t -isc__task_onshutdown(isc_task_t *task0, isc_taskaction_t action, - void *arg); -void -isc__task_shutdown(isc_task_t *task0); -void -isc__task_destroy(isc_task_t **taskp); -void -isc__task_setname(isc_task_t *task0, const char *name, void *tag); -const char * -isc__task_getname(isc_task_t *task0); -void * -isc__task_gettag(isc_task_t *task0); -void -isc__task_getcurrenttime(isc_task_t *task0, time_t *t); -isc_result_t -isc__taskmgr_create(unsigned int workers, - unsigned int default_quantum, isc_taskmgr_t **managerp); -void -isc__taskmgr_destroy(isc_taskmgr_t **managerp); -void -isc_taskmgr_setexcltask(isc_taskmgr_t *mgr0, isc_task_t *task0); -isc_result_t -isc_taskmgr_excltask(isc_taskmgr_t *mgr0, isc_task_t **taskp); -isc_result_t -isc__task_beginexclusive(isc_task_t *task); -void -isc__task_endexclusive(isc_task_t *task0); -void -isc__task_setprivilege(isc_task_t *task0, isc_boolean_t priv); -isc_boolean_t -isc__task_privilege(isc_task_t *task0); -void -isc__taskmgr_setmode(isc_taskmgr_t *manager0, isc_taskmgrmode_t mode); -isc_taskmgrmode_t -isc__taskmgr_mode(isc_taskmgr_t *manager0); +static isc_taskmgr_t *taskmgr = NULL; static inline isc_boolean_t -empty_readyq(isc__taskmgr_t *manager); +empty_readyq(isc_taskmgr_t *manager); -static inline isc__task_t * -pop_readyq(isc__taskmgr_t *manager); +static inline isc_task_t * +pop_readyq(isc_taskmgr_t *manager); static inline void -push_readyq(isc__taskmgr_t *manager, isc__task_t *task); +push_readyq(isc_taskmgr_t *manager, isc_task_t *task); + + /*** *** Tasks. ***/ static void -task_finished(isc__task_t *task) { - isc__taskmgr_t *manager = task->manager; +task_finished(isc_task_t *task) { + isc_taskmgr_t *manager = task->manager; REQUIRE(EMPTY(task->events)); REQUIRE(task->nevents == 0); @@ -205,20 +129,16 @@ task_finished(isc__task_t *task) { UNLINK(manager->tasks, task, link); - task->common.impmagic = 0; - task->common.magic = 0; free(task); } isc_result_t -isc__task_create(isc_taskmgr_t *manager0, unsigned int quantum, +isc_task_create(isc_taskmgr_t *manager, unsigned int quantum, isc_task_t **taskp) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; - isc__task_t *task; + isc_task_t *task; isc_boolean_t exiting; - REQUIRE(VALID_MANAGER(manager)); REQUIRE(taskp != NULL && *taskp == NULL); task = malloc(sizeof(*task)); @@ -252,22 +172,18 @@ isc__task_create(isc_taskmgr_t *manager0, unsigned int quantum, return (ISC_R_SHUTTINGDOWN); } - task->common.magic = ISCAPI_TASK_MAGIC; - task->common.impmagic = TASK_MAGIC; *taskp = (isc_task_t *)task; - return (ISC_R_SUCCESS); } void -isc__task_attach(isc_task_t *source0, isc_task_t **targetp) { - isc__task_t *source = (isc__task_t *)source0; +isc_task_attach(isc_task_t *source0, isc_task_t **targetp) { + isc_task_t *source = (isc_task_t *)source0; /* * Attach *targetp to source. */ - REQUIRE(VALID_TASK(source)); REQUIRE(targetp != NULL && *targetp == NULL); source->references++; @@ -276,7 +192,7 @@ isc__task_attach(isc_task_t *source0, isc_task_t **targetp) { } static inline isc_boolean_t -task_shutdown(isc__task_t *task) { +task_shutdown(isc_task_t *task) { isc_boolean_t was_idle = ISC_FALSE; isc_event_t *event, *prev; @@ -316,17 +232,16 @@ task_shutdown(isc__task_t *task) { * Caller must NOT hold manager lock. */ static inline void -task_ready(isc__task_t *task) { - isc__taskmgr_t *manager = task->manager; +task_ready(isc_task_t *task) { + isc_taskmgr_t *manager = task->manager; - REQUIRE(VALID_MANAGER(manager)); REQUIRE(task->state == task_state_ready); push_readyq(manager, task); } static inline isc_boolean_t -task_detach(isc__task_t *task) { +task_detach(isc_task_t *task) { /* * Caller must be holding the task lock. @@ -353,8 +268,8 @@ task_detach(isc__task_t *task) { } void -isc__task_detach(isc_task_t **taskp) { - isc__task_t *task; +isc_task_detach(isc_task_t **taskp) { + isc_task_t *task; isc_boolean_t was_idle; /* @@ -362,8 +277,7 @@ isc__task_detach(isc_task_t **taskp) { */ REQUIRE(taskp != NULL); - task = (isc__task_t *)*taskp; - REQUIRE(VALID_TASK(task)); + task = (isc_task_t *)*taskp; was_idle = task_detach(task); @@ -374,7 +288,7 @@ isc__task_detach(isc_task_t **taskp) { } static inline isc_boolean_t -task_send(isc__task_t *task, isc_event_t **eventp) { +task_send(isc_task_t *task, isc_event_t **eventp) { isc_boolean_t was_idle = ISC_FALSE; isc_event_t *event; @@ -404,15 +318,13 @@ task_send(isc__task_t *task, isc_event_t **eventp) { } void -isc__task_send(isc_task_t *task0, isc_event_t **eventp) { - isc__task_t *task = (isc__task_t *)task0; +isc_task_send(isc_task_t *task, isc_event_t **eventp) { isc_boolean_t was_idle; /* * Send '*event' to 'task'. */ - REQUIRE(VALID_TASK(task)); /* * We're trying hard to hold locks for as short a time as possible. @@ -442,9 +354,9 @@ isc__task_send(isc_task_t *task0, isc_event_t **eventp) { } void -isc__task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp) { +isc_task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp) { isc_boolean_t idle1, idle2; - isc__task_t *task; + isc_task_t *task; /* * Send '*event' to '*taskp' and then detach '*taskp' from its @@ -452,8 +364,7 @@ isc__task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp) { */ REQUIRE(taskp != NULL); - task = (isc__task_t *)*taskp; - REQUIRE(VALID_TASK(task)); + task = (isc_task_t *)*taskp; idle1 = task_send(task, eventp); idle2 = task_detach(task); @@ -474,14 +385,13 @@ isc__task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp) { #define PURGE_OK(event) (((event)->ev_attributes & ISC_EVENTATTR_NOPURGE) == 0) static unsigned int -dequeue_events(isc__task_t *task, void *sender, isc_eventtype_t first, +dequeue_events(isc_task_t *task, void *sender, isc_eventtype_t first, isc_eventtype_t last, void *tag, isc_eventlist_t *events, isc_boolean_t purging) { isc_event_t *event, *next_event; unsigned int count = 0; - REQUIRE(VALID_TASK(task)); REQUIRE(last >= first); /* @@ -509,10 +419,9 @@ dequeue_events(isc__task_t *task, void *sender, isc_eventtype_t first, } unsigned int -isc__task_purgerange(isc_task_t *task0, void *sender, isc_eventtype_t first, +isc_task_purgerange(isc_task_t *task, void *sender, isc_eventtype_t first, isc_eventtype_t last, void *tag) { - isc__task_t *task = (isc__task_t *)task0; unsigned int count; isc_eventlist_t events; isc_event_t *event, *next_event; @@ -539,20 +448,8 @@ isc__task_purgerange(isc_task_t *task0, void *sender, isc_eventtype_t first, return (count); } -unsigned int -isc__task_purge(isc_task_t *task, void *sender, isc_eventtype_t type, - void *tag) -{ - /* - * Purge events from a task's event queue. - */ - - return (isc__task_purgerange(task, sender, type, type, tag)); -} - isc_boolean_t -isc_task_purgeevent(isc_task_t *task0, isc_event_t *event) { - isc__task_t *task = (isc__task_t *)task0; +isc_task_purgeevent(isc_task_t *task, isc_event_t *event) { isc_event_t *curr_event, *next_event; /* @@ -561,7 +458,6 @@ isc_task_purgeevent(isc_task_t *task0, isc_event_t *event) { * XXXRTH: WARNING: This method may be removed before beta. */ - REQUIRE(VALID_TASK(task)); /* * If 'event' is on the task's event queue, it will be purged, @@ -593,7 +489,7 @@ isc_task_purgeevent(isc_task_t *task0, isc_event_t *event) { } unsigned int -isc__task_unsendrange(isc_task_t *task, void *sender, isc_eventtype_t first, +isc_task_unsendrange(isc_task_t *task, void *sender, isc_eventtype_t first, isc_eventtype_t last, void *tag, isc_eventlist_t *events) { @@ -601,69 +497,30 @@ isc__task_unsendrange(isc_task_t *task, void *sender, isc_eventtype_t first, * Remove events from a task's event queue. */ - return (dequeue_events((isc__task_t *)task, sender, first, + return (dequeue_events((isc_task_t *)task, sender, first, last, tag, events, ISC_FALSE)); } unsigned int -isc__task_unsend(isc_task_t *task, void *sender, isc_eventtype_t type, +isc_task_unsend(isc_task_t *task, void *sender, isc_eventtype_t type, void *tag, isc_eventlist_t *events) { /* * Remove events from a task's event queue. */ - return (dequeue_events((isc__task_t *)task, sender, type, + return (dequeue_events((isc_task_t *)task, sender, type, type, tag, events, ISC_FALSE)); } -isc_result_t -isc__task_onshutdown(isc_task_t *task0, isc_taskaction_t action, - void *arg) -{ - isc__task_t *task = (isc__task_t *)task0; - isc_boolean_t disallowed = ISC_FALSE; - isc_result_t result = ISC_R_SUCCESS; - isc_event_t *event; - - /* - * Send a shutdown event with action 'action' and argument 'arg' when - * 'task' is shutdown. - */ - - REQUIRE(VALID_TASK(task)); - REQUIRE(action != NULL); - - event = isc_event_allocate(NULL, - ISC_TASKEVENT_SHUTDOWN, - action, - arg, - sizeof(*event)); - if (event == NULL) - return (ISC_R_NOMEMORY); - - if (TASK_SHUTTINGDOWN(task)) { - disallowed = ISC_TRUE; - result = ISC_R_SHUTTINGDOWN; - } else - ENQUEUE(task->on_shutdown, event, ev_link); - - if (disallowed) - free(event); - - return (result); -} - void -isc__task_shutdown(isc_task_t *task0) { - isc__task_t *task = (isc__task_t *)task0; +isc_task_shutdown(isc_task_t *task) { isc_boolean_t was_idle; /* * Shutdown 'task'. */ - REQUIRE(VALID_TASK(task)); was_idle = task_shutdown(task); @@ -672,60 +529,26 @@ isc__task_shutdown(isc_task_t *task0) { } void -isc__task_destroy(isc_task_t **taskp) { - - /* - * Destroy '*taskp'. - */ - - REQUIRE(taskp != NULL); - - isc_task_shutdown(*taskp); - isc_task_detach(taskp); -} - -void -isc__task_setname(isc_task_t *task0, const char *name, void *tag) { - isc__task_t *task = (isc__task_t *)task0; - +isc_task_setname(isc_task_t *task, const char *name, void *tag) { /* * Name 'task'. */ - REQUIRE(VALID_TASK(task)); strlcpy(task->name, name, sizeof(task->name)); task->tag = tag; } const char * -isc__task_getname(isc_task_t *task0) { - isc__task_t *task = (isc__task_t *)task0; - - REQUIRE(VALID_TASK(task)); - +isc_task_getname(isc_task_t *task) { return (task->name); } void * -isc__task_gettag(isc_task_t *task0) { - isc__task_t *task = (isc__task_t *)task0; - - REQUIRE(VALID_TASK(task)); - +isc_task_gettag(isc_task_t *task) { return (task->tag); } -void -isc__task_getcurrenttime(isc_task_t *task0, time_t *t) { - isc__task_t *task = (isc__task_t *)task0; - - REQUIRE(VALID_TASK(task)); - REQUIRE(t != NULL); - - *t = task->now; -} - /*** *** Task Manager. ***/ @@ -738,8 +561,8 @@ isc__task_getcurrenttime(isc_task_t *task0, time_t *t) { * Caller must hold the task manager lock. */ static inline isc_boolean_t -empty_readyq(isc__taskmgr_t *manager) { - isc__tasklist_t queue; +empty_readyq(isc_taskmgr_t *manager) { + isc_tasklist_t queue; if (manager->mode == isc_taskmgrmode_normal) queue = manager->ready_tasks; @@ -757,9 +580,9 @@ empty_readyq(isc__taskmgr_t *manager) { * * Caller must hold the task manager lock. */ -static inline isc__task_t * -pop_readyq(isc__taskmgr_t *manager) { - isc__task_t *task; +static inline isc_task_t * +pop_readyq(isc_taskmgr_t *manager) { + isc_task_t *task; if (manager->mode == isc_taskmgrmode_normal) task = HEAD(manager->ready_tasks); @@ -783,7 +606,7 @@ pop_readyq(isc__taskmgr_t *manager) { * Caller must hold the task manager lock. */ static inline void -push_readyq(isc__taskmgr_t *manager, isc__task_t *task) { +push_readyq(isc_taskmgr_t *manager, isc_task_t *task) { ENQUEUE(manager->ready_tasks, task, ready_link); if ((task->flags & TASK_F_PRIVILEGED) != 0) ENQUEUE(manager->ready_priority_tasks, task, @@ -792,14 +615,13 @@ push_readyq(isc__taskmgr_t *manager, isc__task_t *task) { } static void -dispatch(isc__taskmgr_t *manager) { - isc__task_t *task; +dispatch(isc_taskmgr_t *manager) { + isc_task_t *task; unsigned int total_dispatch_count = 0; - isc__tasklist_t new_ready_tasks; - isc__tasklist_t new_priority_tasks; + isc_tasklist_t new_ready_tasks; + isc_tasklist_t new_priority_tasks; unsigned int tasks_ready = 0; - REQUIRE(VALID_MANAGER(manager)); ISC_LIST_INIT(new_ready_tasks); ISC_LIST_INIT(new_priority_tasks); @@ -817,8 +639,6 @@ dispatch(isc__taskmgr_t *manager) { isc_boolean_t finished = ISC_FALSE; isc_event_t *event; - INSIST(VALID_TASK(task)); - /* * Note we only unlock the manager lock if we actually * have a task to do. We must reacquire the manager @@ -955,22 +775,18 @@ dispatch(isc__taskmgr_t *manager) { } static void -manager_free(isc__taskmgr_t *manager) { - - manager->common.impmagic = 0; - manager->common.magic = 0; +manager_free(isc_taskmgr_t *manager) { free(manager); - taskmgr = NULL; } isc_result_t -isc__taskmgr_create(unsigned int workers, +isc_taskmgr_create(unsigned int workers, unsigned int default_quantum, isc_taskmgr_t **managerp) { isc_result_t result; unsigned int i, started = 0; - isc__taskmgr_t *manager; + isc_taskmgr_t *manager; /* * Create a new task manager. @@ -993,8 +809,6 @@ isc__taskmgr_create(unsigned int workers, manager = malloc(sizeof(*manager)); if (manager == NULL) return (ISC_R_NOMEMORY); - manager->common.impmagic = TASK_MANAGER_MAGIC; - manager->common.magic = ISCAPI_TASKMGR_MAGIC; manager->mode = isc_taskmgrmode_normal; if (default_quantum == 0) @@ -1022,9 +836,9 @@ isc__taskmgr_create(unsigned int workers, } void -isc__taskmgr_destroy(isc_taskmgr_t **managerp) { - isc__taskmgr_t *manager; - isc__task_t *task; +isc_taskmgr_destroy(isc_taskmgr_t **managerp) { + isc_taskmgr_t *manager; + isc_task_t *task; unsigned int i; /* @@ -1032,8 +846,7 @@ isc__taskmgr_destroy(isc_taskmgr_t **managerp) { */ REQUIRE(managerp != NULL); - manager = (isc__taskmgr_t *)*managerp; - REQUIRE(VALID_MANAGER(manager)); + manager = (isc_taskmgr_t *)*managerp; UNUSED(i); @@ -1055,7 +868,7 @@ isc__taskmgr_destroy(isc_taskmgr_t **managerp) { * Detach the exclusive task before acquiring the manager lock */ if (manager->excl != NULL) - isc__task_detach((isc_task_t **) &manager->excl); + isc_task_detach((isc_task_t **) &manager->excl); /* * Make sure we only get called once. @@ -1081,8 +894,8 @@ isc__taskmgr_destroy(isc_taskmgr_t **managerp) { /* * Dispatch the shutdown events. */ - while (isc__taskmgr_ready((isc_taskmgr_t *)manager)) - (void)isc__taskmgr_dispatch((isc_taskmgr_t *)manager); + while (isc_taskmgr_ready((isc_taskmgr_t *)manager)) + (void)isc_taskmgr_dispatch((isc_taskmgr_t *)manager); INSIST(ISC_LIST_EMPTY(manager->tasks)); taskmgr = NULL; @@ -1091,24 +904,8 @@ isc__taskmgr_destroy(isc_taskmgr_t **managerp) { *managerp = NULL; } -void -isc__taskmgr_setmode(isc_taskmgr_t *manager0, isc_taskmgrmode_t mode) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; - - manager->mode = mode; -} - -isc_taskmgrmode_t -isc__taskmgr_mode(isc_taskmgr_t *manager0) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; - isc_taskmgrmode_t mode; - mode = manager->mode; - return (mode); -} - isc_boolean_t -isc__taskmgr_ready(isc_taskmgr_t *manager0) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; +isc_taskmgr_ready(isc_taskmgr_t *manager) { isc_boolean_t is_ready; if (manager == NULL) @@ -1122,9 +919,7 @@ isc__taskmgr_ready(isc_taskmgr_t *manager0) { } isc_result_t -isc__taskmgr_dispatch(isc_taskmgr_t *manager0) { - isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; - +isc_taskmgr_dispatch(isc_taskmgr_t *manager) { if (manager == NULL) manager = taskmgr; if (manager == NULL) @@ -1136,171 +931,25 @@ isc__taskmgr_dispatch(isc_taskmgr_t *manager0) { } void -isc_taskmgr_setexcltask(isc_taskmgr_t *mgr0, isc_task_t *task0) { - isc__taskmgr_t *mgr = (isc__taskmgr_t *) mgr0; - isc__task_t *task = (isc__task_t *) task0; +isc_taskmgr_setexcltask(isc_taskmgr_t *mgr0, isc_task_t *task) { + isc_taskmgr_t *mgr = (isc_taskmgr_t *) mgr0; - REQUIRE(VALID_MANAGER(mgr)); - REQUIRE(VALID_TASK(task)); if (mgr->excl != NULL) - isc__task_detach((isc_task_t **) &mgr->excl); - isc__task_attach(task0, (isc_task_t **) &mgr->excl); + isc_task_detach((isc_task_t **) &mgr->excl); + isc_task_attach(task, (isc_task_t **) &mgr->excl); } isc_result_t isc_taskmgr_excltask(isc_taskmgr_t *mgr0, isc_task_t **taskp) { - isc__taskmgr_t *mgr = (isc__taskmgr_t *) mgr0; + isc_taskmgr_t *mgr = (isc_taskmgr_t *) mgr0; isc_result_t result = ISC_R_SUCCESS; - REQUIRE(VALID_MANAGER(mgr)); REQUIRE(taskp != NULL && *taskp == NULL); if (mgr->excl != NULL) - isc__task_attach((isc_task_t *) mgr->excl, taskp); + isc_task_attach((isc_task_t *) mgr->excl, taskp); else result = ISC_R_NOTFOUND; return (result); } - -isc_result_t -isc__task_beginexclusive(isc_task_t *task0) { - UNUSED(task0); - return (ISC_R_SUCCESS); -} - -void -isc__task_endexclusive(isc_task_t *task0) { - UNUSED(task0); -} - -void -isc__task_setprivilege(isc_task_t *task0, isc_boolean_t priv) { - isc__task_t *task = (isc__task_t *)task0; - isc__taskmgr_t *manager = task->manager; - isc_boolean_t oldpriv; - - oldpriv = ISC_TF((task->flags & TASK_F_PRIVILEGED) != 0); - if (priv) - task->flags |= TASK_F_PRIVILEGED; - else - task->flags &= ~TASK_F_PRIVILEGED; - - if (priv == oldpriv) - return; - - if (priv && ISC_LINK_LINKED(task, ready_link)) - ENQUEUE(manager->ready_priority_tasks, task, - ready_priority_link); - else if (!priv && ISC_LINK_LINKED(task, ready_priority_link)) - DEQUEUE(manager->ready_priority_tasks, task, - ready_priority_link); -} - -isc_boolean_t -isc__task_privilege(isc_task_t *task0) { - isc__task_t *task = (isc__task_t *)task0; - isc_boolean_t priv; - - priv = ISC_TF((task->flags & TASK_F_PRIVILEGED) != 0); - return (priv); -} - -isc_result_t -isc_taskmgr_create(unsigned int workers, - unsigned int default_quantum, isc_taskmgr_t **managerp) -{ - return (isc__taskmgr_create(workers, default_quantum, managerp)); -} - -void -isc_taskmgr_destroy(isc_taskmgr_t **managerp) { - REQUIRE(managerp != NULL && ISCAPI_TASKMGR_VALID(*managerp)); - - isc__taskmgr_destroy(managerp); - - ENSURE(*managerp == NULL); -} - -isc_result_t -isc_task_create(isc_taskmgr_t *manager, unsigned int quantum, - isc_task_t **taskp) -{ - REQUIRE(ISCAPI_TASKMGR_VALID(manager)); - REQUIRE(taskp != NULL && *taskp == NULL); - - return (isc__task_create(manager, quantum, taskp)); -} - -void -isc_task_attach(isc_task_t *source, isc_task_t **targetp) { - REQUIRE(ISCAPI_TASK_VALID(source)); - REQUIRE(targetp != NULL && *targetp == NULL); - - isc__task_attach(source, targetp); - - ENSURE(*targetp == source); -} - -void -isc_task_detach(isc_task_t **taskp) { - REQUIRE(taskp != NULL && ISCAPI_TASK_VALID(*taskp)); - - isc__task_detach(taskp); - - ENSURE(*taskp == NULL); -} - -void -isc_task_send(isc_task_t *task, isc_event_t **eventp) { - REQUIRE(ISCAPI_TASK_VALID(task)); - REQUIRE(eventp != NULL && *eventp != NULL); - - isc__task_send(task, eventp); -} - -void -isc_task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp) { - REQUIRE(taskp != NULL && ISCAPI_TASK_VALID(*taskp)); - REQUIRE(eventp != NULL && *eventp != NULL); - - isc__task_sendanddetach(taskp, eventp); - - ENSURE(*taskp == NULL); -} - -unsigned int -isc_task_unsend(isc_task_t *task, void *sender, isc_eventtype_t type, - void *tag, isc_eventlist_t *events) -{ - REQUIRE(ISCAPI_TASK_VALID(task)); - - return (isc__task_unsend(task, sender, type, tag, events)); -} - -void -isc_task_shutdown(isc_task_t *task) { - REQUIRE(ISCAPI_TASK_VALID(task)); - - isc__task_shutdown(task); -} - -void -isc_task_setname(isc_task_t *task, const char *name, void *tag) { - REQUIRE(ISCAPI_TASK_VALID(task)); - - isc__task_setname(task, name, tag); -} - -/*% - * This is necessary for libisc's internal timer implementation. Other - * implementation might skip implementing this. - */ -unsigned int -isc_task_purgerange(isc_task_t *task, void *sender, isc_eventtype_t first, - isc_eventtype_t last, void *tag) -{ - REQUIRE(ISCAPI_TASK_VALID(task)); - - return (isc__task_purgerange(task, sender, first, last, tag)); -} diff --git a/usr.bin/dig/lib/isc/task_p.h b/usr.bin/dig/lib/isc/task_p.h index 35286f2372e..a0163a10cb3 100644 --- a/usr.bin/dig/lib/isc/task_p.h +++ b/usr.bin/dig/lib/isc/task_p.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: task_p.h,v 1.1 2020/02/07 09:58:54 florian Exp $ */ +/* $Id: task_p.h,v 1.2 2020/02/18 18:11:27 florian Exp $ */ #ifndef ISC_TASK_P_H #define ISC_TASK_P_H @@ -22,9 +22,9 @@ /*! \file */ isc_boolean_t -isc__taskmgr_ready(isc_taskmgr_t *taskmgr); +isc_taskmgr_ready(isc_taskmgr_t *taskmgr); isc_result_t -isc__taskmgr_dispatch(isc_taskmgr_t *taskmgr); +isc_taskmgr_dispatch(isc_taskmgr_t *taskmgr); #endif /* ISC_TASK_P_H */ diff --git a/usr.bin/dig/lib/isc/timer.c b/usr.bin/dig/lib/isc/timer.c index 20e472b99f9..b99db8147eb 100644 --- a/usr.bin/dig/lib/isc/timer.c +++ b/usr.bin/dig/lib/isc/timer.c @@ -14,14 +14,13 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: timer.c,v 1.18 2020/02/16 21:11:02 florian Exp $ */ +/* $Id: timer.c,v 1.19 2020/02/18 18:11:27 florian Exp $ */ /*! \file */ #include <stdlib.h> #include <isc/heap.h> -#include <isc/magic.h> #include <isc/task.h> #include <isc/time.h> #include <isc/timer.h> @@ -29,16 +28,12 @@ #include "timer_p.h" -#define TIMER_MAGIC ISC_MAGIC('T', 'I', 'M', 'R') -#define VALID_TIMER(t) ISC_MAGIC_VALID(t, TIMER_MAGIC) +typedef struct isc_timer isc_timer_t; +typedef struct isc_timermgr isc_timermgr_t; -typedef struct isc__timer isc__timer_t; -typedef struct isc__timermgr isc__timermgr_t; - -struct isc__timer { +struct isc_timer { /*! Not locked. */ - isc_timer_t common; - isc__timermgr_t * manager; + isc_timermgr_t * manager; /*! Locked by timer lock. */ unsigned int references; struct timespec idle; @@ -49,18 +44,14 @@ struct isc__timer { void * arg; unsigned int index; struct timespec due; - LINK(isc__timer_t) link; + LINK(isc_timer_t) link; }; -#define TIMER_MANAGER_MAGIC ISC_MAGIC('T', 'I', 'M', 'M') -#define VALID_MANAGER(m) ISC_MAGIC_VALID(m, TIMER_MANAGER_MAGIC) - -struct isc__timermgr { +struct isc_timermgr { /* Not locked. */ - isc_timermgr_t common; /* Locked by manager lock. */ isc_boolean_t done; - LIST(isc__timer_t) timers; + LIST(isc_timer_t) timers; unsigned int nscheduled; struct timespec due; unsigned int refs; @@ -73,33 +64,15 @@ struct isc__timermgr { * unit tests etc. */ -isc_result_t -isc__timer_create(isc_timermgr_t *manager, const struct timespec *interval, - isc_task_t *task, isc_taskaction_t action, void *arg, - isc_timer_t **timerp); -isc_result_t -isc__timer_reset(isc_timer_t *timer, const struct timespec *interval, - isc_boolean_t purge); -void -isc__timer_touch(isc_timer_t *timer); -void -isc__timer_attach(isc_timer_t *timer0, isc_timer_t **timerp); -void -isc__timer_detach(isc_timer_t **timerp); -isc_result_t -isc__timermgr_create(isc_timermgr_t **managerp); -void -isc__timermgr_destroy(isc_timermgr_t **managerp); - /*! * If the manager is supposed to be shared, there can be only one. */ -static isc__timermgr_t *timermgr = NULL; +static isc_timermgr_t *timermgr = NULL; static inline isc_result_t -schedule(isc__timer_t *timer, struct timespec *now, isc_boolean_t signal_ok) { +schedule(isc_timer_t *timer, struct timespec *now, isc_boolean_t signal_ok) { isc_result_t result; - isc__timermgr_t *manager; + isc_timermgr_t *manager; struct timespec due; /*! @@ -152,8 +125,8 @@ schedule(isc__timer_t *timer, struct timespec *now, isc_boolean_t signal_ok) { } static inline void -deschedule(isc__timer_t *timer) { - isc__timermgr_t *manager; +deschedule(isc_timer_t *timer) { + isc_timermgr_t *manager; /* * The caller must ensure locking. @@ -169,8 +142,8 @@ deschedule(isc__timer_t *timer) { } static void -destroy(isc__timer_t *timer) { - isc__timermgr_t *manager = timer->manager; +destroy(isc_timer_t *timer) { + isc_timermgr_t *manager = timer->manager; /* * The caller must ensure it is safe to destroy the timer. @@ -185,18 +158,16 @@ destroy(isc__timer_t *timer) { UNLINK(manager->timers, timer, link); isc_task_detach(&timer->task); - timer->common.impmagic = 0; - timer->common.magic = 0; free(timer); } isc_result_t -isc__timer_create(isc_timermgr_t *manager0, const struct timespec *interval, +isc_timer_create(isc_timermgr_t *manager0, const struct timespec *interval, isc_task_t *task, isc_taskaction_t action, void *arg, isc_timer_t **timerp) { - isc__timermgr_t *manager = (isc__timermgr_t *)manager0; - isc__timer_t *timer; + isc_timermgr_t *manager = (isc_timermgr_t *)manager0; + isc_timer_t *timer; isc_result_t result; struct timespec now; @@ -208,7 +179,6 @@ isc__timer_create(isc_timermgr_t *manager0, const struct timespec *interval, * in 'timerp'. */ - REQUIRE(VALID_MANAGER(manager)); REQUIRE(task != NULL); REQUIRE(action != NULL); REQUIRE(interval != NULL); @@ -247,16 +217,12 @@ isc__timer_create(isc_timermgr_t *manager0, const struct timespec *interval, DE_CONST(arg, timer->arg); timer->index = 0; ISC_LINK_INIT(timer, link); - timer->common.impmagic = TIMER_MAGIC; - timer->common.magic = ISCAPI_TIMER_MAGIC; result = schedule(timer, &now, ISC_TRUE); if (result == ISC_R_SUCCESS) APPEND(manager->timers, timer, link); if (result != ISC_R_SUCCESS) { - timer->common.impmagic = 0; - timer->common.magic = 0; isc_task_detach(&timer->task); free(timer); return (result); @@ -268,12 +234,11 @@ isc__timer_create(isc_timermgr_t *manager0, const struct timespec *interval, } isc_result_t -isc__timer_reset(isc_timer_t *timer0, const struct timespec *interval, +isc_timer_reset(isc_timer_t *timer, const struct timespec *interval, isc_boolean_t purge) { - isc__timer_t *timer = (isc__timer_t *)timer0; struct timespec now; - isc__timermgr_t *manager; + isc_timermgr_t *manager; isc_result_t result; /* @@ -282,9 +247,7 @@ isc__timer_reset(isc_timer_t *timer0, const struct timespec *interval, * are purged from its task's event queue. */ - REQUIRE(VALID_TIMER(timer)); manager = timer->manager; - REQUIRE(VALID_MANAGER(manager)); REQUIRE(interval != NULL); REQUIRE(timespecisset(interval)); @@ -312,39 +275,21 @@ isc__timer_reset(isc_timer_t *timer0, const struct timespec *interval, } void -isc__timer_touch(isc_timer_t *timer0) { - isc__timer_t *timer = (isc__timer_t *)timer0; +isc_timer_touch(isc_timer_t *timer) { struct timespec now; /* * Set the last-touched time of 'timer' to the current time. */ - REQUIRE(VALID_TIMER(timer)); clock_gettime(CLOCK_REALTIME, &now); timespecadd(&now, &timer->interval, &timer->idle); } void -isc__timer_attach(isc_timer_t *timer0, isc_timer_t **timerp) { - isc__timer_t *timer = (isc__timer_t *)timer0; - - /* - * Attach *timerp to timer. - */ - - REQUIRE(VALID_TIMER(timer)); - REQUIRE(timerp != NULL && *timerp == NULL); - - timer->references++; - - *timerp = (isc_timer_t *)timer; -} - -void -isc__timer_detach(isc_timer_t **timerp) { - isc__timer_t *timer; +isc_timer_detach(isc_timer_t **timerp) { + isc_timer_t *timer; isc_boolean_t free_timer = ISC_FALSE; /* @@ -352,8 +297,7 @@ isc__timer_detach(isc_timer_t **timerp) { */ REQUIRE(timerp != NULL); - timer = (isc__timer_t *)*timerp; - REQUIRE(VALID_TIMER(timer)); + timer = (isc_timer_t *)*timerp; REQUIRE(timer->references > 0); timer->references--; @@ -367,11 +311,11 @@ isc__timer_detach(isc_timer_t **timerp) { } static void -dispatch(isc__timermgr_t *manager, struct timespec *now) { +dispatch(isc_timermgr_t *manager, struct timespec *now) { isc_boolean_t done = ISC_FALSE, post_event, need_schedule; isc_timerevent_t *event; isc_eventtype_t type = 0; - isc__timer_t *timer; + isc_timer_t *timer; isc_result_t result; isc_boolean_t idle; @@ -443,12 +387,10 @@ dispatch(isc__timermgr_t *manager, struct timespec *now) { static isc_boolean_t sooner(void *v1, void *v2) { - isc__timer_t *t1, *t2; + isc_timer_t *t1, *t2; t1 = v1; t2 = v2; - REQUIRE(VALID_TIMER(t1)); - REQUIRE(VALID_TIMER(t2)); if (timespeccmp(&t1->due, &t2->due, <)) return (ISC_TRUE); @@ -457,17 +399,16 @@ sooner(void *v1, void *v2) { static void set_index(void *what, unsigned int index) { - isc__timer_t *timer; + isc_timer_t *timer; timer = what; - REQUIRE(VALID_TIMER(timer)); timer->index = index; } isc_result_t -isc__timermgr_create(isc_timermgr_t **managerp) { - isc__timermgr_t *manager; +isc_timermgr_create(isc_timermgr_t **managerp) { + isc_timermgr_t *manager; isc_result_t result; /* @@ -486,8 +427,6 @@ isc__timermgr_create(isc_timermgr_t **managerp) { if (manager == NULL) return (ISC_R_NOMEMORY); - manager->common.impmagic = TIMER_MANAGER_MAGIC; - manager->common.magic = ISCAPI_TIMERMGR_MAGIC; manager->done = ISC_FALSE; INIT_LIST(manager->timers); manager->nscheduled = 0; @@ -508,16 +447,15 @@ isc__timermgr_create(isc_timermgr_t **managerp) { } void -isc__timermgr_destroy(isc_timermgr_t **managerp) { - isc__timermgr_t *manager; +isc_timermgr_destroy(isc_timermgr_t **managerp) { + isc_timermgr_t *manager; /* * Destroy a timer manager. */ REQUIRE(managerp != NULL); - manager = (isc__timermgr_t *)*managerp; - REQUIRE(VALID_MANAGER(manager)); + manager = (isc_timermgr_t *)*managerp; manager->refs--; if (manager->refs > 0) { @@ -526,7 +464,7 @@ isc__timermgr_destroy(isc_timermgr_t **managerp) { } timermgr = NULL; - isc__timermgr_dispatch((isc_timermgr_t *)manager); + isc_timermgr_dispatch((isc_timermgr_t *)manager); REQUIRE(EMPTY(manager->timers)); manager->done = ISC_TRUE; @@ -535,8 +473,6 @@ isc__timermgr_destroy(isc_timermgr_t **managerp) { * Clean up. */ isc_heap_destroy(&manager->heap); - manager->common.impmagic = 0; - manager->common.magic = 0; free(manager); *managerp = NULL; @@ -545,8 +481,8 @@ isc__timermgr_destroy(isc_timermgr_t **managerp) { } isc_result_t -isc__timermgr_nextevent(isc_timermgr_t *manager0, struct timespec *when) { - isc__timermgr_t *manager = (isc__timermgr_t *)manager0; +isc_timermgr_nextevent(isc_timermgr_t *manager0, struct timespec *when) { + isc_timermgr_t *manager = (isc_timermgr_t *)manager0; if (manager == NULL) manager = timermgr; @@ -557,8 +493,8 @@ isc__timermgr_nextevent(isc_timermgr_t *manager0, struct timespec *when) { } void -isc__timermgr_dispatch(isc_timermgr_t *manager0) { - isc__timermgr_t *manager = (isc__timermgr_t *)manager0; +isc_timermgr_dispatch(isc_timermgr_t *manager0) { + isc_timermgr_t *manager = (isc_timermgr_t *)manager0; struct timespec now; if (manager == NULL) @@ -569,52 +505,3 @@ isc__timermgr_dispatch(isc_timermgr_t *manager0) { dispatch(manager, &now); } -isc_result_t -isc_timermgr_create(isc_timermgr_t **managerp) { - return (isc__timermgr_create(managerp)); -} - -void -isc_timermgr_destroy(isc_timermgr_t **managerp) { - REQUIRE(*managerp != NULL && ISCAPI_TIMERMGR_VALID(*managerp)); - - isc__timermgr_destroy(managerp); - - ENSURE(*managerp == NULL); -} - -isc_result_t -isc_timer_create(isc_timermgr_t *manager, const struct timespec *interval, - isc_task_t *task, isc_taskaction_t action, void *arg, - isc_timer_t **timerp) -{ - REQUIRE(ISCAPI_TIMERMGR_VALID(manager)); - - return (isc__timer_create(manager, interval, - task, action, arg, timerp)); -} - -void -isc_timer_detach(isc_timer_t **timerp) { - REQUIRE(timerp != NULL && ISCAPI_TIMER_VALID(*timerp)); - - isc__timer_detach(timerp); - - ENSURE(*timerp == NULL); -} - -isc_result_t -isc_timer_reset(isc_timer_t *timer, const struct timespec *interval, - isc_boolean_t purge) -{ - REQUIRE(ISCAPI_TIMER_VALID(timer)); - - return (isc__timer_reset(timer, interval, purge)); -} - -void -isc_timer_touch(isc_timer_t *timer) { - REQUIRE(ISCAPI_TIMER_VALID(timer)); - - isc__timer_touch(timer); -} diff --git a/usr.bin/dig/lib/isc/timer_p.h b/usr.bin/dig/lib/isc/timer_p.h index c3a95313869..ec287c36911 100644 --- a/usr.bin/dig/lib/isc/timer_p.h +++ b/usr.bin/dig/lib/isc/timer_p.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: timer_p.h,v 1.2 2020/02/16 18:05:09 florian Exp $ */ +/* $Id: timer_p.h,v 1.3 2020/02/18 18:11:27 florian Exp $ */ #ifndef ISC_TIMER_P_H #define ISC_TIMER_P_H @@ -22,9 +22,9 @@ /*! \file */ isc_result_t -isc__timermgr_nextevent(isc_timermgr_t *timermgr, struct timespec *when); +isc_timermgr_nextevent(isc_timermgr_t *timermgr, struct timespec *when); void -isc__timermgr_dispatch(isc_timermgr_t *timermgr); +isc_timermgr_dispatch(isc_timermgr_t *timermgr); #endif /* ISC_TIMER_P_H */ diff --git a/usr.bin/dig/lib/isc/unix/app.c b/usr.bin/dig/lib/isc/unix/app.c index 555079e0bb7..e06046316e2 100644 --- a/usr.bin/dig/lib/isc/unix/app.c +++ b/usr.bin/dig/lib/isc/unix/app.c @@ -16,8 +16,6 @@ /*! \file */ - - #include <stddef.h> #include <stdlib.h> #include <errno.h> @@ -26,8 +24,6 @@ #include <isc/app.h> #include <isc/boolean.h> - - #include <isc/event.h> #include <string.h> @@ -45,43 +41,12 @@ #include "../task_p.h" #include "socket_p.h" -/*% - * The following are intended for internal use (indicated by "isc__" - * prefix) but are not declared as static, allowing direct access from - * unit tests etc. - */ -isc_result_t isc__app_start(void); -isc_result_t isc__app_ctxstart(isc_appctx_t *ctx); -isc_result_t isc__app_onrun(isc_task_t *task, - isc_taskaction_t action, void *arg); -isc_result_t isc__app_ctxrun(isc_appctx_t *ctx); -isc_result_t isc__app_run(void); -isc_result_t isc__app_ctxshutdown(isc_appctx_t *ctx); -isc_result_t isc__app_shutdown(void); -isc_result_t isc__app_reload(void); -isc_result_t isc__app_ctxsuspend(isc_appctx_t *ctx); -void isc__app_ctxfinish(isc_appctx_t *ctx); -void isc__app_finish(void); -void isc__app_block(void); -void isc__app_unblock(void); -isc_result_t isc__appctx_create(isc_appctx_t **ctxp); -void isc__appctx_destroy(isc_appctx_t **ctxp); -void isc__appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr); -void isc__appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr); -void isc__appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr); -isc_result_t isc__app_ctxonrun(isc_appctx_t *ctx, - isc_task_t *task, isc_taskaction_t action, - void *arg); - /* * The application context of this module. This implementation actually * doesn't use it. (This may change in the future). */ -#define APPCTX_MAGIC ISC_MAGIC('A', 'p', 'c', 'x') -#define VALID_APPCTX(c) ISC_MAGIC_VALID(c, APPCTX_MAGIC) -typedef struct isc__appctx { - isc_appctx_t common; +typedef struct isc_appctx { isc_eventlist_t on_run; isc_boolean_t shutdown_requested; isc_boolean_t running; @@ -100,9 +65,13 @@ typedef struct isc__appctx { isc_taskmgr_t *taskmgr; isc_socketmgr_t *socketmgr; isc_timermgr_t *timermgr; -} isc__appctx_t; +} isc_appctx_t; + +static isc_appctx_t isc_g_appctx; +static isc_boolean_t is_running = ISC_FALSE; -static isc__appctx_t isc_g_appctx; +static isc_result_t isc_app_ctxonrun(isc_appctx_t *ctx, isc_task_t *task, + isc_taskaction_t action, void *arg); static void reload_action(int arg) { @@ -128,15 +97,12 @@ handle_signal(int sig, void (*handler)(int)) { return (ISC_R_SUCCESS); } -isc_result_t -isc__app_ctxstart(isc_appctx_t *ctx0) { - isc__appctx_t *ctx = (isc__appctx_t *)ctx0; +static isc_result_t +isc_app_ctxstart(isc_appctx_t *ctx) { isc_result_t result; int presult; sigset_t sset; - REQUIRE(VALID_APPCTX(ctx)); - /* * Start an ISC library application. */ @@ -209,27 +175,24 @@ isc__app_ctxstart(isc_appctx_t *ctx0) { } isc_result_t -isc__app_start(void) { - isc_g_appctx.common.impmagic = APPCTX_MAGIC; - isc_g_appctx.common.magic = ISCAPI_APPCTX_MAGIC; +isc_app_start(void) { /* The remaining members will be initialized in ctxstart() */ - return (isc__app_ctxstart((isc_appctx_t *)&isc_g_appctx)); + return (isc_app_ctxstart((isc_appctx_t *)&isc_g_appctx)); } isc_result_t -isc__app_onrun(isc_task_t *task, isc_taskaction_t action, +isc_app_onrun(isc_task_t *task, isc_taskaction_t action, void *arg) { - return (isc__app_ctxonrun((isc_appctx_t *)&isc_g_appctx, + return (isc_app_ctxonrun((isc_appctx_t *)&isc_g_appctx, task, action, arg)); } isc_result_t -isc__app_ctxonrun(isc_appctx_t *ctx0, isc_task_t *task, +isc_app_ctxonrun(isc_appctx_t *ctx, isc_task_t *task, isc_taskaction_t action, void *arg) { - isc__appctx_t *ctx = (isc__appctx_t *)ctx0; isc_event_t *event; isc_task_t *cloned_task = NULL; isc_result_t result; @@ -264,7 +227,7 @@ isc__app_ctxonrun(isc_appctx_t *ctx0, isc_task_t *task, * Event loop for nonthreaded programs. */ static isc_result_t -evloop(isc__appctx_t *ctx) { +evloop(isc_appctx_t *ctx) { isc_result_t result; while (!ctx->want_shutdown) { @@ -278,8 +241,8 @@ evloop(isc__appctx_t *ctx) { /* * Check the reload (or suspend) case first for exiting the * loop as fast as possible in case: - * - the direct call to isc__taskmgr_dispatch() in - * isc__app_ctxrun() completes all the tasks so far, + * - the direct call to isc_taskmgr_dispatch() in + * isc_app_ctxrun() completes all the tasks so far, * - there is thus currently no active task, and * - there is a timer event */ @@ -288,14 +251,14 @@ evloop(isc__appctx_t *ctx) { return (ISC_R_RELOAD); } - readytasks = isc__taskmgr_ready(ctx->taskmgr); + readytasks = isc_taskmgr_ready(ctx->taskmgr); if (readytasks) { tv.tv_sec = 0; tv.tv_usec = 0; tvp = &tv; call_timer_dispatch = ISC_TRUE; } else { - result = isc__timermgr_nextevent(ctx->timermgr, &when); + result = isc_timermgr_nextevent(ctx->timermgr, &when); if (result != ISC_R_SUCCESS) tvp = NULL; else { @@ -312,11 +275,11 @@ evloop(isc__appctx_t *ctx) { } swait = NULL; - n = isc__socketmgr_waitevents(ctx->socketmgr, tvp, &swait); + n = isc_socketmgr_waitevents(ctx->socketmgr, tvp, &swait); if (n == 0 || call_timer_dispatch) { /* - * We call isc__timermgr_dispatch() only when + * We call isc_timermgr_dispatch() only when * necessary, in order to reduce overhead. If the * select() call indicates a timeout, we need the * dispatch. Even if not, if we set the 0-timeout @@ -329,24 +292,21 @@ evloop(isc__appctx_t *ctx) { * call, since this loop only runs in the non-thread * mode. */ - isc__timermgr_dispatch(ctx->timermgr); + isc_timermgr_dispatch(ctx->timermgr); } if (n > 0) - (void)isc__socketmgr_dispatch(ctx->socketmgr, swait); - (void)isc__taskmgr_dispatch(ctx->taskmgr); + (void)isc_socketmgr_dispatch(ctx->socketmgr, swait); + (void)isc_taskmgr_dispatch(ctx->taskmgr); } return (ISC_R_SUCCESS); } -isc_result_t -isc__app_ctxrun(isc_appctx_t *ctx0) { - isc__appctx_t *ctx = (isc__appctx_t *)ctx0; +static isc_result_t +isc_app_ctxrun(isc_appctx_t *ctx) { int result; isc_event_t *event, *next_event; isc_task_t *task; - REQUIRE(VALID_APPCTX(ctx)); - if (!ctx->running) { ctx->running = ISC_TRUE; @@ -371,23 +331,20 @@ isc__app_ctxrun(isc_appctx_t *ctx0) { return (ISC_R_SUCCESS); } - (void) isc__taskmgr_dispatch(ctx->taskmgr); + (void) isc_taskmgr_dispatch(ctx->taskmgr); result = evloop(ctx); return (result); } isc_result_t -isc__app_run(void) { - return (isc__app_ctxrun((isc_appctx_t *)&isc_g_appctx)); +isc_app_run(void) { + return (isc_app_ctxrun((isc_appctx_t *)&isc_g_appctx)); } -isc_result_t -isc__app_ctxshutdown(isc_appctx_t *ctx0) { - isc__appctx_t *ctx = (isc__appctx_t *)ctx0; +static isc_result_t +isc_app_ctxshutdown(isc_appctx_t *ctx) { isc_boolean_t want_kill = ISC_TRUE; - REQUIRE(VALID_APPCTX(ctx)); - REQUIRE(ctx->running); if (ctx->shutdown_requested) @@ -407,57 +364,18 @@ isc__app_ctxshutdown(isc_appctx_t *ctx0) { return (ISC_R_SUCCESS); } -isc_result_t -isc__app_shutdown(void) { - return (isc__app_ctxshutdown((isc_appctx_t *)&isc_g_appctx)); -} - -isc_result_t -isc__app_ctxsuspend(isc_appctx_t *ctx0) { - isc__appctx_t *ctx = (isc__appctx_t *)ctx0; - isc_boolean_t want_kill = ISC_TRUE; - - REQUIRE(VALID_APPCTX(ctx)); - - REQUIRE(ctx->running); - - /* - * Don't send the reload signal if we're shutting down. - */ - if (ctx->shutdown_requested) - want_kill = ISC_FALSE; - - if (want_kill) { - if (ctx != &isc_g_appctx) - /* BIND9 internal, but using multiple contexts */ - ctx->want_reload = ISC_TRUE; - else { - ctx->want_reload = ISC_TRUE; - } - } - - return (ISC_R_SUCCESS); +isc_boolean_t +isc_app_isrunning() { + return (is_running); } isc_result_t -isc__app_reload(void) { - return (isc__app_ctxsuspend((isc_appctx_t *)&isc_g_appctx)); +isc_app_shutdown(void) { + return (isc_app_ctxshutdown((isc_appctx_t *)&isc_g_appctx)); } void -isc__app_ctxfinish(isc_appctx_t *ctx0) { - isc__appctx_t *ctx = (isc__appctx_t *)ctx0; - - REQUIRE(VALID_APPCTX(ctx)); -} - -void -isc__app_finish(void) { - isc__app_ctxfinish((isc_appctx_t *)&isc_g_appctx); -} - -void -isc__app_block(void) { +isc_app_block(void) { REQUIRE(isc_g_appctx.running); REQUIRE(!isc_g_appctx.blocked); @@ -465,7 +383,7 @@ isc__app_block(void) { } void -isc__app_unblock(void) { +isc_app_unblock(void) { REQUIRE(isc_g_appctx.running); REQUIRE(isc_g_appctx.blocked); @@ -473,67 +391,3 @@ isc__app_unblock(void) { isc_g_appctx.blocked = ISC_FALSE; } - -isc_result_t -isc__appctx_create(isc_appctx_t **ctxp) { - isc__appctx_t *ctx; - - REQUIRE(ctxp != NULL && *ctxp == NULL); - - ctx = malloc(sizeof(*ctx)); - if (ctx == NULL) - return (ISC_R_NOMEMORY); - - ctx->common.impmagic = APPCTX_MAGIC; - ctx->common.magic = ISCAPI_APPCTX_MAGIC; - - ctx->taskmgr = NULL; - ctx->socketmgr = NULL; - ctx->timermgr = NULL; - - *ctxp = (isc_appctx_t *)ctx; - - return (ISC_R_SUCCESS); -} - -void -isc__appctx_destroy(isc_appctx_t **ctxp) { - isc__appctx_t *ctx; - - REQUIRE(ctxp != NULL); - ctx = (isc__appctx_t *)*ctxp; - REQUIRE(VALID_APPCTX(ctx)); - - free(ctx); - - *ctxp = NULL; -} - -void -isc__appctx_settaskmgr(isc_appctx_t *ctx0, isc_taskmgr_t *taskmgr) { - isc__appctx_t *ctx = (isc__appctx_t *)ctx0; - - REQUIRE(VALID_APPCTX(ctx)); - - ctx->taskmgr = taskmgr; -} - -void -isc__appctx_setsocketmgr(isc_appctx_t *ctx0, isc_socketmgr_t *socketmgr) { - isc__appctx_t *ctx = (isc__appctx_t *)ctx0; - - REQUIRE(VALID_APPCTX(ctx)); - - ctx->socketmgr = socketmgr; -} - -void -isc__appctx_settimermgr(isc_appctx_t *ctx0, isc_timermgr_t *timermgr) { - isc__appctx_t *ctx = (isc__appctx_t *)ctx0; - - REQUIRE(VALID_APPCTX(ctx)); - - ctx->timermgr = timermgr; -} - -#include "../app_api.c" diff --git a/usr.bin/dig/lib/isc/unix/socket.c b/usr.bin/dig/lib/isc/unix/socket.c index c6ce5c328e2..4af3b7529d3 100644 --- a/usr.bin/dig/lib/isc/unix/socket.c +++ b/usr.bin/dig/lib/isc/unix/socket.c @@ -97,9 +97,6 @@ int isc_dscp_check_value = -1; typedef isc_event_t intev_t; -#define SOCKET_MAGIC ISC_MAGIC('I', 'O', 'i', 'o') -#define VALID_SOCKET(s) ISC_MAGIC_VALID(s, SOCKET_MAGIC) - /*! * IPv6 control information. If the socket is an IPv6 socket we want * to collect the destination address and interface so the client can @@ -134,17 +131,16 @@ typedef isc_event_t intev_t; */ #define NRETRIES 10 -typedef struct isc__socket isc__socket_t; -typedef struct isc__socketmgr isc__socketmgr_t; +typedef struct isc_socket isc_socket_t; +typedef struct isc_socketmgr isc_socketmgr_t; -struct isc__socket { +struct isc_socket { /* Not locked. */ - isc_socket_t common; - isc__socketmgr_t *manager; + isc_socketmgr_t *manager; isc_sockettype_t type; /* Locked by socket lock. */ - ISC_LINK(isc__socket_t) link; + ISC_LINK(isc_socket_t) link; unsigned int references; int fd; int pf; @@ -173,20 +169,16 @@ struct isc__socket { unsigned int dscp; }; -#define SOCKET_MANAGER_MAGIC ISC_MAGIC('I', 'O', 'm', 'g') -#define VALID_MANAGER(m) ISC_MAGIC_VALID(m, SOCKET_MANAGER_MAGIC) - -struct isc__socketmgr { +struct isc_socketmgr { /* Not locked. */ - isc_socketmgr_t common; int fd_bufsize; unsigned int maxsocks; - isc__socket_t **fds; + isc_socket_t **fds; int *fdstate; /* Locked by manager lock. */ - ISC_LIST(isc__socket_t) socklist; + ISC_LIST(isc_socket_t) socklist; fd_set *read_fds; fd_set *read_fds_copy; fd_set *write_fds; @@ -195,7 +187,7 @@ struct isc__socketmgr { unsigned int refs; }; -static isc__socketmgr_t *socketmgr = NULL; +static isc_socketmgr_t *socketmgr = NULL; #define CLOSED 0 /* this one must be zero */ #define MANAGED 1 @@ -210,64 +202,21 @@ static isc__socketmgr_t *socketmgr = NULL; static isc_result_t socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, isc_socket_t **socketp); -static void send_recvdone_event(isc__socket_t *, isc_socketevent_t **); -static void send_senddone_event(isc__socket_t *, isc_socketevent_t **); -static void free_socket(isc__socket_t **); -static isc_result_t allocate_socket(isc__socketmgr_t *, isc_sockettype_t, - isc__socket_t **); -static void destroy(isc__socket_t **); +static void send_recvdone_event(isc_socket_t *, isc_socketevent_t **); +static void send_senddone_event(isc_socket_t *, isc_socketevent_t **); +static void free_socket(isc_socket_t **); +static isc_result_t allocate_socket(isc_socketmgr_t *, isc_sockettype_t, + isc_socket_t **); +static void destroy(isc_socket_t **); static void internal_connect(isc_task_t *, isc_event_t *); static void internal_recv(isc_task_t *, isc_event_t *); static void internal_send(isc_task_t *, isc_event_t *); -static void process_cmsg(isc__socket_t *, struct msghdr *, isc_socketevent_t *); -static void build_msghdr_send(isc__socket_t *, char *, isc_socketevent_t *, +static void process_cmsg(isc_socket_t *, struct msghdr *, isc_socketevent_t *); +static void build_msghdr_send(isc_socket_t *, char *, isc_socketevent_t *, struct msghdr *, struct iovec *, size_t *); -static void build_msghdr_recv(isc__socket_t *, char *, isc_socketevent_t *, +static void build_msghdr_recv(isc_socket_t *, char *, isc_socketevent_t *, struct msghdr *, struct iovec *, size_t *); -/*% - * The following are intended for internal use (indicated by "isc__" - * prefix) but are not declared as static, allowing direct access from - * unit tests etc. - */ - -isc_result_t -isc__socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, - isc_socket_t **socketp); -void -isc__socket_attach(isc_socket_t *sock, isc_socket_t **socketp); -void -isc__socket_detach(isc_socket_t **socketp); -isc_result_t -isc__socket_recvv(isc_socket_t *sock, isc_bufferlist_t *buflist, - unsigned int minimum, isc_task_t *task, - isc_taskaction_t action, void *arg); -isc_result_t -isc__socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist, - isc_task_t *task, isc_taskaction_t action, void *arg); -isc_result_t -isc__socket_sendtov2(isc_socket_t *sock, isc_bufferlist_t *buflist, - isc_task_t *task, isc_taskaction_t action, void *arg, - isc_sockaddr_t *address, struct in6_pktinfo *pktinfo, - unsigned int flags); -isc_result_t -isc__socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr, - unsigned int options); -isc_result_t -isc__socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr, - isc_task_t *task, isc_taskaction_t action, - void *arg); -void -isc__socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how); - -isc_result_t -isc__socketmgr_create(isc_socketmgr_t **managerp); -isc_result_t -isc__socketmgr_create2(isc_socketmgr_t **managerp, - unsigned int maxsocks); -void -isc__socketmgr_destroy(isc_socketmgr_t **managerp); - #define SELECT_POKE_SHUTDOWN (-1) #define SELECT_POKE_READ (-3) #define SELECT_POKE_WRITE (-4) @@ -295,11 +244,11 @@ enum { static void -socket_log(isc__socket_t *sock, isc_sockaddr_t *address, +socket_log(isc_socket_t *sock, isc_sockaddr_t *address, isc_logcategory_t *category, isc_logmodule_t *module, int level, const char *fmt, ...) __attribute__((__format__(__printf__, 6, 7))); static void -socket_log(isc__socket_t *sock, isc_sockaddr_t *address, +socket_log(isc_socket_t *sock, isc_sockaddr_t *address, isc_logcategory_t *category, isc_logmodule_t *module, int level, const char *fmt, ...) { @@ -325,7 +274,7 @@ socket_log(isc__socket_t *sock, isc_sockaddr_t *address, } static inline isc_result_t -watch_fd(isc__socketmgr_t *manager, int fd, int msg) { +watch_fd(isc_socketmgr_t *manager, int fd, int msg) { isc_result_t result = ISC_R_SUCCESS; if (msg == SELECT_POKE_READ) @@ -337,7 +286,7 @@ watch_fd(isc__socketmgr_t *manager, int fd, int msg) { } static inline isc_result_t -unwatch_fd(isc__socketmgr_t *manager, int fd, int msg) { +unwatch_fd(isc_socketmgr_t *manager, int fd, int msg) { isc_result_t result = ISC_R_SUCCESS; if (msg == SELECT_POKE_READ) @@ -349,7 +298,7 @@ unwatch_fd(isc__socketmgr_t *manager, int fd, int msg) { } static void -wakeup_socket(isc__socketmgr_t *manager, int fd, int msg) { +wakeup_socket(isc_socketmgr_t *manager, int fd, int msg) { isc_result_t result; /* @@ -406,7 +355,7 @@ wakeup_socket(isc__socketmgr_t *manager, int fd, int msg) { * Update the state of the socketmgr when something changes. */ static void -select_poke(isc__socketmgr_t *manager, int fd, int msg) { +select_poke(isc_socketmgr_t *manager, int fd, int msg) { if (msg == SELECT_POKE_SHUTDOWN) return; else if (fd >= 0) @@ -457,7 +406,7 @@ cmsg_space(socklen_t len) { * Process control messages received on a socket. */ static void -process_cmsg(isc__socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) { +process_cmsg(isc_socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) { struct cmsghdr *cmsgp; struct in6_pktinfo *pktinfop; void *timevalp; @@ -548,7 +497,7 @@ process_cmsg(isc__socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) { * this transaction can send. */ static void -build_msghdr_send(isc__socket_t *sock, char* cmsgbuf, isc_socketevent_t *dev, +build_msghdr_send(isc_socket_t *sock, char* cmsgbuf, isc_socketevent_t *dev, struct msghdr *msg, struct iovec *iov, size_t *write_countp) { unsigned int iovcount; @@ -590,7 +539,6 @@ build_msghdr_send(isc__socket_t *sock, char* cmsgbuf, isc_socketevent_t *dev, */ skip_count = dev->n; while (buffer != NULL) { - REQUIRE(ISC_BUFFER_VALID(buffer)); if (skip_count < isc_buffer_usedlength(buffer)) break; skip_count -= isc_buffer_usedlength(buffer); @@ -748,7 +696,7 @@ build_msghdr_send(isc__socket_t *sock, char* cmsgbuf, isc_socketevent_t *dev, * this transaction can receive. */ static void -build_msghdr_recv(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, +build_msghdr_recv(isc_socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, struct msghdr *msg, struct iovec *iov, size_t *read_countp) { unsigned int iovcount; @@ -788,7 +736,6 @@ build_msghdr_recv(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, * Skip empty buffers. */ while (buffer != NULL) { - REQUIRE(ISC_BUFFER_VALID(buffer)); if (isc_buffer_availablelength(buffer) != 0) break; buffer = ISC_LIST_NEXT(buffer, link); @@ -826,7 +773,7 @@ build_msghdr_recv(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, } static void -set_dev_address(isc_sockaddr_t *address, isc__socket_t *sock, +set_dev_address(isc_sockaddr_t *address, isc_socket_t *sock, isc_socketevent_t *dev) { if (sock->type == isc_sockettype_udp) { @@ -883,7 +830,7 @@ allocate_socketevent(void *sender, #define DOIO_EOF 3 /* EOF, no event sent */ static int -doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) { +doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { int cc; struct iovec iov[MAXSCATTERGATHER_RECV]; size_t read_count; @@ -994,7 +941,6 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) { actual_count = cc; buffer = ISC_LIST_HEAD(dev->bufferlist); while (buffer != NULL && actual_count > 0U) { - REQUIRE(ISC_BUFFER_VALID(buffer)); if (isc_buffer_availablelength(buffer) <= actual_count) { actual_count -= isc_buffer_availablelength(buffer); isc_buffer_add(buffer, @@ -1039,7 +985,7 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) { * No other return values are possible. */ static int -doio_send(isc__socket_t *sock, isc_socketevent_t *dev) { +doio_send(isc_socket_t *sock, isc_socketevent_t *dev) { int cc; struct iovec iov[MAXSCATTERGATHER_SEND]; size_t write_count; @@ -1140,7 +1086,7 @@ doio_send(isc__socket_t *sock, isc_socketevent_t *dev) { * references exist. */ static void -socketclose(isc__socketmgr_t *manager, isc__socket_t *sock, int fd) { +socketclose(isc_socketmgr_t *manager, isc_socket_t *sock, int fd) { /* * No one has this socket open, so the watcher doesn't have to be * poked, and the socket doesn't have to be locked. @@ -1172,10 +1118,10 @@ socketclose(isc__socketmgr_t *manager, isc__socket_t *sock, int fd) { } static void -destroy(isc__socket_t **sockp) { +destroy(isc_socket_t **sockp) { int fd; - isc__socket_t *sock = *sockp; - isc__socketmgr_t *manager = sock->manager; + isc_socket_t *sock = *sockp; + isc_socketmgr_t *manager = sock->manager; socket_log(sock, NULL, CREATION, "destroying"); @@ -1197,18 +1143,16 @@ destroy(isc__socket_t **sockp) { } static isc_result_t -allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type, - isc__socket_t **socketp) +allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type, + isc_socket_t **socketp) { - isc__socket_t *sock; + isc_socket_t *sock; sock = malloc(sizeof(*sock)); if (sock == NULL) return (ISC_R_NOMEMORY); - sock->common.magic = 0; - sock->common.impmagic = 0; sock->references = 0; sock->manager = manager; @@ -1242,8 +1186,6 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type, ISC_EVENTATTR_NOPURGE, NULL, ISC_SOCKEVENT_INTW, NULL, sock, sock, NULL); - sock->common.magic = ISCAPI_SOCKET_MAGIC; - sock->common.impmagic = SOCKET_MAGIC; *socketp = sock; return (ISC_R_SUCCESS); @@ -1251,16 +1193,15 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type, /* * This event requires that the various lists be empty, that the reference - * count be 1, and that the magic number is valid. The other socket bits, + * count be 1. The other socket bits, * like the lock, must be initialized as well. The fd associated must be * marked as closed, by setting it to -1 on close, or this routine will * also close the socket. */ static void -free_socket(isc__socket_t **socketp) { - isc__socket_t *sock = *socketp; +free_socket(isc_socket_t **socketp) { + isc_socket_t *sock = *socketp; - INSIST(VALID_SOCKET(sock)); INSIST(sock->references == 0); INSIST(!sock->connecting); INSIST(!sock->pending_recv); @@ -1269,16 +1210,13 @@ free_socket(isc__socket_t **socketp) { INSIST(ISC_LIST_EMPTY(sock->send_list)); INSIST(!ISC_LINK_LINKED(sock, link)); - sock->common.magic = 0; - sock->common.impmagic = 0; - free(sock); *socketp = NULL; } static void -use_min_mtu(isc__socket_t *sock) { +use_min_mtu(isc_socket_t *sock) { /* use minimum MTU */ if (sock->pf == AF_INET6) { int on = 1; @@ -1288,14 +1226,14 @@ use_min_mtu(isc__socket_t *sock) { } static void -set_tcp_maxseg(isc__socket_t *sock, int size) { +set_tcp_maxseg(isc_socket_t *sock, int size) { if (sock->type == isc_sockettype_tcp) (void)setsockopt(sock->fd, IPPROTO_TCP, TCP_MAXSEG, (void *)&size, sizeof(size)); } static isc_result_t -opensocket(isc__socket_t *sock) +opensocket(isc_socket_t *sock) { isc_result_t result; const char *err = "socket"; @@ -1392,11 +1330,10 @@ static isc_result_t socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, isc_socket_t **socketp) { - isc__socket_t *sock = NULL; - isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0; + isc_socket_t *sock = NULL; + isc_socketmgr_t *manager = (isc_socketmgr_t *)manager0; isc_result_t result; - REQUIRE(VALID_MANAGER(manager)); REQUIRE(socketp != NULL && *socketp == NULL); result = allocate_socket(manager, type, &sock); @@ -1449,7 +1386,7 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, * in 'socketp'. */ isc_result_t -isc__socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, +isc_socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, isc_socket_t **socketp) { return (socket_create(manager0, pf, type, socketp)); @@ -1459,10 +1396,9 @@ isc__socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, * Attach to a socket. Caller must explicitly detach when it is done. */ void -isc__socket_attach(isc_socket_t *sock0, isc_socket_t **socketp) { - isc__socket_t *sock = (isc__socket_t *)sock0; +isc_socket_attach(isc_socket_t *sock0, isc_socket_t **socketp) { + isc_socket_t *sock = (isc_socket_t *)sock0; - REQUIRE(VALID_SOCKET(sock)); REQUIRE(socketp != NULL && *socketp == NULL); sock->references++; @@ -1475,13 +1411,12 @@ isc__socket_attach(isc_socket_t *sock0, isc_socket_t **socketp) { * up by destroying the socket. */ void -isc__socket_detach(isc_socket_t **socketp) { - isc__socket_t *sock; +isc_socket_detach(isc_socket_t **socketp) { + isc_socket_t *sock; isc_boolean_t kill_socket = ISC_FALSE; REQUIRE(socketp != NULL); - sock = (isc__socket_t *)*socketp; - REQUIRE(VALID_SOCKET(sock)); + sock = (isc_socket_t *)*socketp; REQUIRE(sock->references > 0); sock->references--; @@ -1503,7 +1438,7 @@ isc__socket_detach(isc_socket_t **socketp) { * The socket and manager must be locked before calling this function. */ static void -dispatch_recv(isc__socket_t *sock) { +dispatch_recv(isc_socket_t *sock) { intev_t *iev; isc_socketevent_t *ev; isc_task_t *sender; @@ -1530,7 +1465,7 @@ dispatch_recv(isc__socket_t *sock) { } static void -dispatch_send(isc__socket_t *sock) { +dispatch_send(isc_socket_t *sock) { intev_t *iev; isc_socketevent_t *ev; isc_task_t *sender; @@ -1557,7 +1492,7 @@ dispatch_send(isc__socket_t *sock) { } static void -dispatch_connect(isc__socket_t *sock) { +dispatch_connect(isc_socket_t *sock) { intev_t *iev; isc_socket_connev_t *ev; @@ -1587,7 +1522,7 @@ dispatch_connect(isc__socket_t *sock) { * Caller must have the socket locked if the event is attached to the socket. */ static void -send_recvdone_event(isc__socket_t *sock, isc_socketevent_t **dev) { +send_recvdone_event(isc_socket_t *sock, isc_socketevent_t **dev) { isc_task_t *task; task = (*dev)->ev_sender; @@ -1610,7 +1545,7 @@ send_recvdone_event(isc__socket_t *sock, isc_socketevent_t **dev) { * Caller must have the socket locked if the event is attached to the socket. */ static void -send_senddone_event(isc__socket_t *sock, isc_socketevent_t **dev) { +send_senddone_event(isc_socket_t *sock, isc_socketevent_t **dev) { isc_task_t *task; INSIST(dev != NULL && *dev != NULL); @@ -1631,12 +1566,11 @@ send_senddone_event(isc__socket_t *sock, isc_socketevent_t **dev) { static void internal_recv(isc_task_t *me, isc_event_t *ev) { isc_socketevent_t *dev; - isc__socket_t *sock; + isc_socket_t *sock; INSIST(ev->ev_type == ISC_SOCKEVENT_INTR); sock = ev->ev_sender; - INSIST(VALID_SOCKET(sock)); socket_log(sock, NULL, IOEVENT, "internal_recv: task %p got event %p", me, ev); @@ -1691,15 +1625,14 @@ internal_recv(isc_task_t *me, isc_event_t *ev) { static void internal_send(isc_task_t *me, isc_event_t *ev) { isc_socketevent_t *dev; - isc__socket_t *sock; + isc_socket_t *sock; INSIST(ev->ev_type == ISC_SOCKEVENT_INTW); /* * Find out what socket this is and lock it. */ - sock = (isc__socket_t *)ev->ev_sender; - INSIST(VALID_SOCKET(sock)); + sock = (isc_socket_t *)ev->ev_sender; socket_log(sock, NULL, IOEVENT, "internal_send: task %p got event %p", me, ev); @@ -1742,10 +1675,10 @@ internal_send(isc_task_t *me, isc_event_t *ev) { * and unlocking twice if both reads and writes are possible. */ static void -process_fd(isc__socketmgr_t *manager, int fd, isc_boolean_t readable, +process_fd(isc_socketmgr_t *manager, int fd, isc_boolean_t readable, isc_boolean_t writeable) { - isc__socket_t *sock; + isc_socket_t *sock; isc_boolean_t unwatch_read = ISC_FALSE, unwatch_write = ISC_FALSE; /* @@ -1792,7 +1725,7 @@ check_write: } static void -process_fds(isc__socketmgr_t *manager, int maxfd, fd_set *readfds, +process_fds(isc_socketmgr_t *manager, int maxfd, fd_set *readfds, fd_set *writefds) { int i; @@ -1810,7 +1743,7 @@ process_fds(isc__socketmgr_t *manager, int maxfd, fd_set *readfds, */ static isc_result_t -setup_watcher(isc__socketmgr_t *manager) { +setup_watcher(isc_socketmgr_t *manager) { isc_result_t result; UNUSED(result); @@ -1851,7 +1784,7 @@ setup_watcher(isc__socketmgr_t *manager) { } static void -cleanup_watcher(isc__socketmgr_t *manager) { +cleanup_watcher(isc_socketmgr_t *manager) { if (manager->read_fds != NULL) free(manager->read_fds); @@ -1863,16 +1796,11 @@ cleanup_watcher(isc__socketmgr_t *manager) { free(manager->write_fds_copy); } -isc_result_t -isc__socketmgr_create(isc_socketmgr_t **managerp) { - return (isc__socketmgr_create2(managerp, 0)); -} - -isc_result_t -isc__socketmgr_create2(isc_socketmgr_t **managerp, +static isc_result_t +isc_socketmgr_create2(isc_socketmgr_t **managerp, unsigned int maxsocks) { - isc__socketmgr_t *manager; + isc_socketmgr_t *manager; isc_result_t result; REQUIRE(managerp != NULL && *managerp == NULL); @@ -1897,7 +1825,7 @@ isc__socketmgr_create2(isc_socketmgr_t **managerp, /* zero-clear so that necessary cleanup on failure will be easy */ memset(manager, 0, sizeof(*manager)); manager->maxsocks = maxsocks; - manager->fds = malloc(manager->maxsocks * sizeof(isc__socket_t *)); + manager->fds = malloc(manager->maxsocks * sizeof(isc_socket_t *)); if (manager->fds == NULL) { result = ISC_R_NOMEMORY; goto free_manager; @@ -1908,8 +1836,6 @@ isc__socketmgr_create2(isc_socketmgr_t **managerp, goto free_manager; } - manager->common.magic = ISCAPI_SOCKETMGR_MAGIC; - manager->common.impmagic = SOCKET_MANAGER_MAGIC; memset(manager->fds, 0, manager->maxsocks * sizeof(isc_socket_t *)); ISC_LIST_INIT(manager->socklist); @@ -1943,9 +1869,14 @@ free_manager: return (result); } +isc_result_t +isc_socketmgr_create(isc_socketmgr_t **managerp) { + return (isc_socketmgr_create2(managerp, 0)); +} + void -isc__socketmgr_destroy(isc_socketmgr_t **managerp) { - isc__socketmgr_t *manager; +isc_socketmgr_destroy(isc_socketmgr_t **managerp) { + isc_socketmgr_t *manager; int i; /* @@ -1953,8 +1884,7 @@ isc__socketmgr_destroy(isc_socketmgr_t **managerp) { */ REQUIRE(managerp != NULL); - manager = (isc__socketmgr_t *)*managerp; - REQUIRE(VALID_MANAGER(manager)); + manager = (isc_socketmgr_t *)*managerp; manager->refs--; if (manager->refs > 0) { @@ -1967,7 +1897,7 @@ isc__socketmgr_destroy(isc_socketmgr_t **managerp) { * Wait for all sockets to be destroyed. */ while (!ISC_LIST_EMPTY(manager->socklist)) { - isc__taskmgr_dispatch(NULL); + isc_taskmgr_dispatch(NULL); } /* @@ -1989,8 +1919,6 @@ isc__socketmgr_destroy(isc_socketmgr_t **managerp) { free(manager->fds); free(manager->fdstate); - manager->common.magic = 0; - manager->common.impmagic = 0; free(manager); *managerp = NULL; @@ -1999,7 +1927,7 @@ isc__socketmgr_destroy(isc_socketmgr_t **managerp) { } static isc_result_t -socket_recv(isc__socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, +socket_recv(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, unsigned int flags) { int io_state; @@ -2059,24 +1987,22 @@ socket_recv(isc__socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, } isc_result_t -isc__socket_recvv(isc_socket_t *sock0, isc_bufferlist_t *buflist, +isc_socket_recvv(isc_socket_t *sock0, isc_bufferlist_t *buflist, unsigned int minimum, isc_task_t *task, isc_taskaction_t action, void *arg) { - isc__socket_t *sock = (isc__socket_t *)sock0; + isc_socket_t *sock = (isc_socket_t *)sock0; isc_socketevent_t *dev; - isc__socketmgr_t *manager; + isc_socketmgr_t *manager; unsigned int iocount; isc_buffer_t *buffer; - REQUIRE(VALID_SOCKET(sock)); REQUIRE(buflist != NULL); REQUIRE(!ISC_LIST_EMPTY(*buflist)); REQUIRE(task != NULL); REQUIRE(action != NULL); manager = sock->manager; - REQUIRE(VALID_MANAGER(manager)); iocount = isc_bufferlist_availablecount(buflist); REQUIRE(iocount > 0); @@ -2114,7 +2040,7 @@ isc__socket_recvv(isc_socket_t *sock0, isc_bufferlist_t *buflist, } static isc_result_t -socket_send(isc__socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, +socket_send(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, isc_sockaddr_t *address, struct in6_pktinfo *pktinfo, unsigned int flags) { @@ -2195,33 +2121,31 @@ socket_send(isc__socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, } isc_result_t -isc__socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist, +isc_socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist, isc_task_t *task, isc_taskaction_t action, void *arg) { - return (isc__socket_sendtov2(sock, buflist, task, action, arg, NULL, + return (isc_socket_sendtov2(sock, buflist, task, action, arg, NULL, NULL, 0)); } isc_result_t -isc__socket_sendtov2(isc_socket_t *sock0, isc_bufferlist_t *buflist, +isc_socket_sendtov2(isc_socket_t *sock0, isc_bufferlist_t *buflist, isc_task_t *task, isc_taskaction_t action, void *arg, isc_sockaddr_t *address, struct in6_pktinfo *pktinfo, unsigned int flags) { - isc__socket_t *sock = (isc__socket_t *)sock0; + isc_socket_t *sock = (isc_socket_t *)sock0; isc_socketevent_t *dev; - isc__socketmgr_t *manager; + isc_socketmgr_t *manager; unsigned int iocount; isc_buffer_t *buffer; - REQUIRE(VALID_SOCKET(sock)); REQUIRE(buflist != NULL); REQUIRE(!ISC_LIST_EMPTY(*buflist)); REQUIRE(task != NULL); REQUIRE(action != NULL); manager = sock->manager; - REQUIRE(VALID_MANAGER(manager)); iocount = isc_bufferlist_usedcount(buflist); REQUIRE(iocount > 0); @@ -2245,13 +2169,11 @@ isc__socket_sendtov2(isc_socket_t *sock0, isc_bufferlist_t *buflist, } isc_result_t -isc__socket_bind(isc_socket_t *sock0, isc_sockaddr_t *sockaddr, +isc_socket_bind(isc_socket_t *sock0, isc_sockaddr_t *sockaddr, unsigned int options) { - isc__socket_t *sock = (isc__socket_t *)sock0; + isc_socket_t *sock = (isc_socket_t *)sock0; int on = 1; - REQUIRE(VALID_SOCKET(sock)); - INSIST(!sock->bound); if (sock->pf != sockaddr->type.sa.sa_family) { @@ -2293,23 +2215,21 @@ isc__socket_bind(isc_socket_t *sock0, isc_sockaddr_t *sockaddr, } isc_result_t -isc__socket_connect(isc_socket_t *sock0, isc_sockaddr_t *addr, +isc_socket_connect(isc_socket_t *sock0, isc_sockaddr_t *addr, isc_task_t *task, isc_taskaction_t action, void *arg) { - isc__socket_t *sock = (isc__socket_t *)sock0; + isc_socket_t *sock = (isc_socket_t *)sock0; isc_socket_connev_t *dev; isc_task_t *ntask = NULL; - isc__socketmgr_t *manager; + isc_socketmgr_t *manager; int cc; char addrbuf[ISC_SOCKADDR_FORMATSIZE]; - REQUIRE(VALID_SOCKET(sock)); REQUIRE(addr != NULL); REQUIRE(task != NULL); REQUIRE(action != NULL); manager = sock->manager; - REQUIRE(VALID_MANAGER(manager)); REQUIRE(addr != NULL); if (isc_sockaddr_ismulticast(addr)) @@ -2420,7 +2340,7 @@ isc__socket_connect(isc_socket_t *sock0, isc_sockaddr_t *addr, */ static void internal_connect(isc_task_t *me, isc_event_t *ev) { - isc__socket_t *sock; + isc_socket_t *sock; isc_socket_connev_t *dev; isc_task_t *task; int cc; @@ -2431,7 +2351,6 @@ internal_connect(isc_task_t *me, isc_event_t *ev) { INSIST(ev->ev_type == ISC_SOCKEVENT_INTW); sock = ev->ev_sender; - INSIST(VALID_SOCKET(sock)); /* * When the internal event was sent the reference count was bumped @@ -2523,10 +2442,8 @@ internal_connect(isc_task_t *me, isc_event_t *ev) { * queued for task "task" of type "how". "how" is a bitmask. */ void -isc__socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) { - isc__socket_t *sock = (isc__socket_t *)sock0; - - REQUIRE(VALID_SOCKET(sock)); +isc_socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) { + isc_socket_t *sock = (isc_socket_t *)sock0; /* * Quick exit if there is nothing to do. Don't even bother locking @@ -2619,10 +2536,10 @@ isc__socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) { static isc_socketwait_t swait_private; int -isc__socketmgr_waitevents(isc_socketmgr_t *manager0, struct timeval *tvp, +isc_socketmgr_waitevents(isc_socketmgr_t *manager0, struct timeval *tvp, isc_socketwait_t **swaitp) { - isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0; + isc_socketmgr_t *manager = (isc_socketmgr_t *)manager0; int n; REQUIRE(swaitp != NULL && *swaitp == NULL); @@ -2648,8 +2565,8 @@ isc__socketmgr_waitevents(isc_socketmgr_t *manager0, struct timeval *tvp, } isc_result_t -isc__socketmgr_dispatch(isc_socketmgr_t *manager0, isc_socketwait_t *swait) { - isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0; +isc_socketmgr_dispatch(isc_socketmgr_t *manager0, isc_socketwait_t *swait) { + isc_socketmgr_t *manager = (isc_socketmgr_t *)manager0; REQUIRE(swait == &swait_private); @@ -2661,5 +2578,3 @@ isc__socketmgr_dispatch(isc_socketmgr_t *manager0, isc_socketwait_t *swait) { process_fds(manager, swait->maxfd, swait->readset, swait->writeset); return (ISC_R_SUCCESS); } - -#include "../socket_api.c" diff --git a/usr.bin/dig/lib/isc/unix/socket_p.h b/usr.bin/dig/lib/isc/unix/socket_p.h index ec3a83042a5..84f52f045bb 100644 --- a/usr.bin/dig/lib/isc/unix/socket_p.h +++ b/usr.bin/dig/lib/isc/unix/socket_p.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket_p.h,v 1.1 2020/02/07 09:58:54 florian Exp $ */ +/* $Id: socket_p.h,v 1.2 2020/02/18 18:11:27 florian Exp $ */ #ifndef ISC_SOCKET_P_H #define ISC_SOCKET_P_H @@ -24,7 +24,7 @@ #include <sys/select.h> typedef struct isc_socketwait isc_socketwait_t; -int isc__socketmgr_waitevents(isc_socketmgr_t *, struct timeval *, +int isc_socketmgr_waitevents(isc_socketmgr_t *, struct timeval *, isc_socketwait_t **); -isc_result_t isc__socketmgr_dispatch(isc_socketmgr_t *, isc_socketwait_t *); +isc_result_t isc_socketmgr_dispatch(isc_socketmgr_t *, isc_socketwait_t *); #endif /* ISC_SOCKET_P_H */ diff --git a/usr.bin/dig/nslookup.c b/usr.bin/dig/nslookup.c index 4944a5ffbe3..5422aa8a08f 100644 --- a/usr.bin/dig/nslookup.c +++ b/usr.bin/dig/nslookup.c @@ -913,7 +913,6 @@ nslookup_main(int argc, char **argv) { isc_event_free(&global_event); cancel_all(); destroy_libs(); - isc_app_finish(); return (query_error | print_error); } |