From 15060430f07dac80fb5a9d0714fbe3752039e706 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Sun, 15 Dec 2019 16:45:17 -0800 Subject: [PATCH] style cleanup clean up style in rndc and the control channel in preparation for changing them to use the new network manager. --- bin/named/controlconf.c | 131 ++++++++++++++++------------------- bin/rndc/rndc.c | 25 +++---- doc/misc/options | 36 +++++----- doc/misc/options.active | 36 +++++----- doc/misc/options.grammar.rst | 15 ++-- lib/isccc/ccmsg.c | 45 ++++-------- 6 files changed, 135 insertions(+), 153 deletions(-) diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c index a3fda486d3..90a8eafb33 100644 --- a/bin/named/controlconf.c +++ b/bin/named/controlconf.c @@ -198,8 +198,8 @@ maybe_free_connection(controlconnection_t *conn) { static void shutdown_listener(controllistener_t *listener) { - controlconnection_t *conn; - controlconnection_t *next; + controlconnection_t *conn = NULL; + controlconnection_t *next = NULL; if (!listener->exiting) { char socktext[ISC_SOCKADDR_FORMATSIZE]; @@ -340,7 +340,7 @@ control_recvmessage(isc_task_t *task, isc_event_t *event) { isc_stdtime_t now; isc_buffer_t b; isc_region_t r; - isc_buffer_t *text; + isc_buffer_t *text = NULL; isc_result_t result; isc_result_t eresult; isccc_sexpr_t *_ctrl = NULL; @@ -572,7 +572,7 @@ control_timeout(isc_task_t *task, isc_event_t *event) { static isc_result_t newconnection(controllistener_t *listener, isc_socket_t *sock) { - controlconnection_t *conn; + controlconnection_t *conn = NULL; isc_interval_t interval; isc_result_t result; @@ -630,7 +630,7 @@ static void control_newconn(isc_task_t *task, isc_event_t *event) { isc_socket_newconnev_t *nevent = (isc_socket_newconnev_t *)event; controllistener_t *listener = event->ev_arg; - isc_socket_t *sock; + isc_socket_t *sock = NULL; isc_sockaddr_t peeraddr; isc_result_t result; @@ -682,8 +682,8 @@ cleanup: static void controls_shutdown(named_controls_t *controls) { - controllistener_t *listener; - controllistener_t *next; + controllistener_t *listener = NULL; + controllistener_t *next = NULL; for (listener = ISC_LIST_HEAD(controls->listeners); listener != NULL; listener = next) @@ -706,9 +706,9 @@ named_controls_shutdown(named_controls_t *controls) { static isc_result_t cfgkeylist_find(const cfg_obj_t *keylist, const char *keyname, const cfg_obj_t **objp) { - const cfg_listelt_t *element; - const char *str; - const cfg_obj_t *obj; + const cfg_listelt_t *element = NULL; + const char *str = NULL; + const cfg_obj_t *obj = NULL; for (element = cfg_list_first(keylist); element != NULL; element = cfg_list_next(element)) @@ -730,11 +730,11 @@ cfgkeylist_find(const cfg_obj_t *keylist, const char *keyname, static void controlkeylist_fromcfg(const cfg_obj_t *keylist, isc_mem_t *mctx, controlkeylist_t *keyids) { - const cfg_listelt_t *element; + const cfg_listelt_t *element = NULL; char *newstr = NULL; - const char *str; - const cfg_obj_t *obj; - controlkey_t *key; + const char *str = NULL; + const cfg_obj_t *obj = NULL; + controlkey_t *key = NULL; for (element = cfg_list_first(keylist); element != NULL; element = cfg_list_next(element)) @@ -756,8 +756,8 @@ controlkeylist_fromcfg(const cfg_obj_t *keylist, isc_mem_t *mctx, static void register_keys(const cfg_obj_t *control, const cfg_obj_t *keylist, controlkeylist_t *keyids, isc_mem_t *mctx, const char *socktext) { - controlkey_t *keyid, *next; - const cfg_obj_t *keydef; + controlkey_t *keyid = NULL, *next = NULL; + const cfg_obj_t *keydef = NULL; char secret[1024]; isc_buffer_t b; isc_result_t result; @@ -790,10 +790,9 @@ register_keys(const cfg_obj_t *control, const cfg_obj_t *keylist, algstr = cfg_obj_asstring(algobj); secretstr = cfg_obj_asstring(secretobj); - if (named_config_getkeyalgorithm2(algstr, NULL, - &algtype, NULL) != - ISC_R_SUCCESS) - { + result = named_config_getkeyalgorithm2(algstr, NULL, + &algtype, NULL); + if (result != ISC_R_SUCCESS) { cfg_obj_log(control, named_g_lctx, ISC_LOG_WARNING, "unsupported algorithm '%s' in " @@ -830,11 +829,12 @@ register_keys(const cfg_obj_t *control, const cfg_obj_t *keylist, } } -#define CHECK(x) \ - do { \ - result = (x); \ - if (result != ISC_R_SUCCESS) \ - goto cleanup; \ +#define CHECK(x) \ + do { \ + result = (x); \ + if (result != ISC_R_SUCCESS) { \ + goto cleanup; \ + } \ } while (0) static isc_result_t @@ -884,9 +884,8 @@ get_rndckey(isc_mem_t *mctx, controlkeylist_t *keyids) { algstr = cfg_obj_asstring(algobj); secretstr = cfg_obj_asstring(secretobj); - if (named_config_getkeyalgorithm2(algstr, NULL, &algtype, NULL) != - ISC_R_SUCCESS) - { + result = named_config_getkeyalgorithm2(algstr, NULL, &algtype, NULL); + if (result != ISC_R_SUCCESS) { cfg_obj_log(key, named_g_lctx, ISC_LOG_WARNING, "unsupported algorithm '%s' in " "key '%s' for use with command " @@ -959,8 +958,8 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp, const cfg_obj_t *control, const cfg_obj_t *config, isc_sockaddr_t *addr, cfg_aclconfctx_t *aclconfctx, const char *socktext, isc_sockettype_t type) { - controllistener_t *listener; - const cfg_obj_t *allow; + controllistener_t *listener = NULL; + const cfg_obj_t *allow = NULL; const cfg_obj_t *global_keylist = NULL; const cfg_obj_t *control_keylist = NULL; dns_acl_t *new_acl = NULL; @@ -1053,7 +1052,7 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp, } if (control != NULL) { - const cfg_obj_t *readonly; + const cfg_obj_t *readonly = NULL; readonly = cfg_tuple_get(control, "read-only"); if (!cfg_obj_isvoid(readonly)) { @@ -1112,49 +1111,36 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp, isc_sockaddr_t *addr, cfg_aclconfctx_t *aclconfctx, const char *socktext, isc_sockettype_t type) { isc_mem_t *mctx = cp->server->mctx; - controllistener_t *listener; - const cfg_obj_t *allow; + controllistener_t *listener = NULL; + const cfg_obj_t *allow = NULL; const cfg_obj_t *global_keylist = NULL; const cfg_obj_t *control_keylist = NULL; dns_acl_t *new_acl = NULL; isc_result_t result = ISC_R_SUCCESS; listener = isc_mem_get(mctx, sizeof(*listener)); + *listener = (controllistener_t){ .controls = cp, + .task = cp->server->task, + .address = *addr, + .type = type }; + isc_mem_attach(mctx, &listener->mctx); + ISC_LINK_INIT(listener, link); + ISC_LIST_INIT(listener->keys); + ISC_LIST_INIT(listener->connections); - if (result == ISC_R_SUCCESS) { - listener->mctx = NULL; - isc_mem_attach(mctx, &listener->mctx); - listener->controls = cp; - listener->task = cp->server->task; - listener->address = *addr; - listener->sock = NULL; - listener->listening = false; - listener->exiting = false; - listener->acl = NULL; - listener->type = type; - listener->perm = 0; - listener->owner = 0; - listener->group = 0; - listener->readonly = false; - ISC_LINK_INIT(listener, link); - ISC_LIST_INIT(listener->keys); - ISC_LIST_INIT(listener->connections); - - /* - * Make the acl. - */ - if (control != NULL && type == isc_sockettype_tcp) { - allow = cfg_tuple_get(control, "allow"); - result = cfg_acl_fromconfig(allow, config, named_g_lctx, - aclconfctx, mctx, 0, - &new_acl); - } else { - result = dns_acl_any(mctx, &new_acl); - } + /* + * Make the ACL. + */ + if (control != NULL && type == isc_sockettype_tcp) { + allow = cfg_tuple_get(control, "allow"); + result = cfg_acl_fromconfig(allow, config, named_g_lctx, + aclconfctx, mctx, 0, &new_acl); + } else { + result = dns_acl_any(mctx, &new_acl); } - if ((result == ISC_R_SUCCESS) && (control != NULL)) { - const cfg_obj_t *readonly; + if (result == ISC_R_SUCCESS && control != NULL) { + const cfg_obj_t *readonly = NULL; readonly = cfg_tuple_get(control, "read-only"); if (!cfg_obj_isvoid(readonly)) { @@ -1234,6 +1220,7 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp, result = isc_socket_permunix(&listener->address, listener->perm, listener->owner, listener->group); } + if (result == ISC_R_SUCCESS) { result = control_listen(listener); } @@ -1273,7 +1260,7 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp, isc_result_t named_controls_configure(named_controls_t *cp, const cfg_obj_t *config, cfg_aclconfctx_t *aclconfctx) { - controllistener_t *listener; + controllistener_t *listener = NULL; controllistenerlist_t new_listeners; const cfg_obj_t *controlslist = NULL; const cfg_listelt_t *element, *element2; @@ -1298,7 +1285,7 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config, for (element = cfg_list_first(controlslist); element != NULL; element = cfg_list_next(element)) { - const cfg_obj_t *controls; + const cfg_obj_t *controls = NULL; const cfg_obj_t *inetcontrols = NULL; controls = cfg_listelt_value(element); @@ -1311,8 +1298,8 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config, element2 != NULL; element2 = cfg_list_next(element2)) { - const cfg_obj_t *control; - const cfg_obj_t *obj; + const cfg_obj_t *control = NULL; + const cfg_obj_t *obj = NULL; isc_sockaddr_t addr; /* @@ -1369,7 +1356,7 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config, for (element = cfg_list_first(controlslist); element != NULL; element = cfg_list_next(element)) { - const cfg_obj_t *controls; + const cfg_obj_t *controls = NULL; const cfg_obj_t *unixcontrols = NULL; controls = cfg_listelt_value(element); @@ -1382,8 +1369,8 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config, element2 != NULL; element2 = cfg_list_next(element2)) { - const cfg_obj_t *control; - const cfg_obj_t *path; + const cfg_obj_t *control = NULL; + const cfg_obj_t *path = NULL; isc_sockaddr_t addr; isc_result_t result; diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index ba91747657..6b780d738e 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -55,11 +55,11 @@ #define SERVERADDRS 10 -const char *progname; +const char *progname = NULL; bool verbose; -static const char *admin_conffile; -static const char *admin_keyfile; +static const char *admin_conffile = NULL; +static const char *admin_keyfile = NULL; static const char *version = PACKAGE_VERSION; static const char *servername = NULL; static isc_sockaddr_t serveraddrs[SERVERADDRS]; @@ -69,18 +69,18 @@ static int nserveraddrs; static int currentaddr = 0; static unsigned int remoteport = 0; static isc_socketmgr_t *socketmgr = NULL; -static isc_buffer_t *databuf; +static isc_buffer_t *databuf = NULL; static isccc_ccmsg_t ccmsg; static uint32_t algorithm; static isccc_region_t secret; static bool failed = false; static bool c_flag = false; -static isc_mem_t *rndc_mctx; +static isc_mem_t *rndc_mctx = NULL; static atomic_uint_fast32_t sends = ATOMIC_VAR_INIT(0); static atomic_uint_fast32_t recvs = ATOMIC_VAR_INIT(0); static atomic_uint_fast32_t connects = ATOMIC_VAR_INIT(0); -static char *command; -static char *args; +static char *command = NULL; +static char *args = NULL; static char program[256]; static isc_socket_t *sock = NULL; static uint32_t serial; @@ -111,7 +111,7 @@ command is one of the following:\n\ Close, rename and re-open the DNSTAP output file(s).\n\ dumpdb [-all|-cache|-zones|-adb|-bad|-fail] [view ...]\n\ Dump cache(s) to the dump file (named_dump.db).\n\ - flush Flushes all of the server's caches.\n\ + flush Flushes all of the server's caches.\n\ flush [view] Flushes the server's cache for a view.\n\ flushname name [view]\n\ Flush the given name from the server's cache(s)\n\ @@ -649,7 +649,7 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname, if (servers != NULL) { for (elt = cfg_list_first(servers); elt != NULL; elt = cfg_list_next(elt)) { - const char *name; + const char *name = NULL; server = cfg_listelt_value(elt); name = cfg_obj_asstring( cfg_map_getname(server)); @@ -686,9 +686,11 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname, DO("get config key list", cfg_map_get(config, "key", &keys)); for (elt = cfg_list_first(keys); elt != NULL; elt = cfg_list_next(elt)) { + const char *name = NULL; + key = cfg_listelt_value(elt); - if (strcasecmp(cfg_obj_asstring(cfg_map_getname(key)), - keyname) == 0) { + name = cfg_obj_asstring(cfg_map_getname(key)); + if (strcasecmp(name, keyname) == 0) { break; } } @@ -987,7 +989,6 @@ main(int argc, char **argv) { DO("create task manager", isc_taskmgr_create(rndc_mctx, 1, 0, NULL, &taskmgr)); DO("create task", isc_task_create(taskmgr, 0, &task)); - isc_log_create(rndc_mctx, &log, &logconfig); isc_log_setcontext(log); isc_log_settag(logconfig, progname); diff --git a/doc/misc/options b/doc/misc/options index ea9242ef67..5161474545 100644 --- a/doc/misc/options +++ b/doc/misc/options @@ -166,13 +166,16 @@ options { dnssec-secure-to-insecure ; dnssec-update-mode ( maintain | no-resign ); dnssec-validation ( yes | no | auto ); - dnstap { ( all | auth | client | forwarder | resolver | update ) [ - ( query | response ) ]; ... }; - dnstap-identity ( | none | hostname ); - dnstap-output ( file | unix ) [ size ( unlimited | - ) ] [ versions ( unlimited | ) ] [ suffix ( - increment | timestamp ) ]; - dnstap-version ( | none ); + dnstap { ( all | auth | client | forwarder | + resolver | update ) [ ( query | response ) ]; + ... }; // not configured + dnstap-identity ( | none | + hostname ); // not configured + dnstap-output ( file | unix ) [ + size ( unlimited | ) ] [ versions ( + unlimited | ) ] [ suffix ( increment + | timestamp ) ]; // not configured + dnstap-version ( | none ); // not configured dscp ; dual-stack-servers [ port ] { ( [ port ] [ dscp ] | [ port @@ -196,13 +199,13 @@ options { forward ( first | only ); forwarders [ port ] [ dscp ] { ( | ) [ port ] [ dscp ]; ... }; - fstrm-set-buffer-hint ; - fstrm-set-flush-timeout ; - fstrm-set-input-queue-size ; - fstrm-set-output-notify-threshold ; - fstrm-set-output-queue-model ( mpsc | spsc ); - fstrm-set-output-queue-size ; - fstrm-set-reopen-interval ; + fstrm-set-buffer-hint ; // not configured + fstrm-set-flush-timeout ; // not configured + fstrm-set-input-queue-size ; // not configured + fstrm-set-output-notify-threshold ; // not configured + fstrm-set-output-queue-model ( mpsc | spsc ); // not configured + fstrm-set-output-queue-size ; // not configured + fstrm-set-reopen-interval ; // not configured geoip-directory ( | none ); geoip-use-ecs ; // obsolete glue-cache ; @@ -547,8 +550,9 @@ view [ ] { dnssec-secure-to-insecure ; dnssec-update-mode ( maintain | no-resign ); dnssec-validation ( yes | no | auto ); - dnstap { ( all | auth | client | forwarder | resolver | update ) [ - ( query | response ) ]; ... }; + dnstap { ( all | auth | client | forwarder | + resolver | update ) [ ( query | response ) ]; + ... }; // not configured dual-stack-servers [ port ] { ( [ port ] [ dscp ] | [ port ] [ dscp ] | [ port diff --git a/doc/misc/options.active b/doc/misc/options.active index 40dec8ba63..95f69709ca 100644 --- a/doc/misc/options.active +++ b/doc/misc/options.active @@ -153,13 +153,16 @@ options { dnssec-secure-to-insecure ; dnssec-update-mode ( maintain | no-resign ); dnssec-validation ( yes | no | auto ); - dnstap { ( all | auth | client | forwarder | resolver | update ) [ - ( query | response ) ]; ... }; - dnstap-identity ( | none | hostname ); - dnstap-output ( file | unix ) [ size ( unlimited | - ) ] [ versions ( unlimited | ) ] [ suffix ( - increment | timestamp ) ]; - dnstap-version ( | none ); + dnstap { ( all | auth | client | forwarder | + resolver | update ) [ ( query | response ) ]; + ... }; // not configured + dnstap-identity ( | none | + hostname ); // not configured + dnstap-output ( file | unix ) [ + size ( unlimited | ) ] [ versions ( + unlimited | ) ] [ suffix ( increment + | timestamp ) ]; // not configured + dnstap-version ( | none ); // not configured dscp ; dual-stack-servers [ port ] { ( [ port ] [ dscp ] | [ port @@ -178,13 +181,13 @@ options { forward ( first | only ); forwarders [ port ] [ dscp ] { ( | ) [ port ] [ dscp ]; ... }; - fstrm-set-buffer-hint ; - fstrm-set-flush-timeout ; - fstrm-set-input-queue-size ; - fstrm-set-output-notify-threshold ; - fstrm-set-output-queue-model ( mpsc | spsc ); - fstrm-set-output-queue-size ; - fstrm-set-reopen-interval ; + fstrm-set-buffer-hint ; // not configured + fstrm-set-flush-timeout ; // not configured + fstrm-set-input-queue-size ; // not configured + fstrm-set-output-notify-threshold ; // not configured + fstrm-set-output-queue-model ( mpsc | spsc ); // not configured + fstrm-set-output-queue-size ; // not configured + fstrm-set-reopen-interval ; // not configured geoip-directory ( | none ); glue-cache ; heartbeat-interval ; @@ -492,8 +495,9 @@ view [ ] { dnssec-secure-to-insecure ; dnssec-update-mode ( maintain | no-resign ); dnssec-validation ( yes | no | auto ); - dnstap { ( all | auth | client | forwarder | resolver | update ) [ - ( query | response ) ]; ... }; + dnstap { ( all | auth | client | forwarder | + resolver | update ) [ ( query | response ) ]; + ... }; // not configured dual-stack-servers [ port ] { ( [ port ] [ dscp ] | [ port ] [ dscp ] | [ port diff --git a/doc/misc/options.grammar.rst b/doc/misc/options.grammar.rst index f7d9657b75..d99a89fbcc 100644 --- a/doc/misc/options.grammar.rst +++ b/doc/misc/options.grammar.rst @@ -82,12 +82,15 @@ dnssec-secure-to-insecure ; dnssec-update-mode ( maintain | no-resign ); dnssec-validation ( yes | no | auto ); - dnstap { ( all | auth | client | forwarder | resolver | update ) [ - ( query | response ) ]; ... }; - dnstap-identity ( | none | hostname ); - dnstap-output ( file | unix ) [ size ( unlimited | - ) ] [ versions ( unlimited | ) ] [ suffix ( - increment | timestamp ) ]; + dnstap { ( all | auth | client | forwarder | + resolver | update ) [ ( query | response ) ]; + ... }; + dnstap-identity ( | none | + hostname ); + dnstap-output ( file | unix ) [ + size ( unlimited | ) ] [ versions ( + unlimited | ) ] [ suffix ( increment + | timestamp ) ]; dnstap-version ( | none ); dscp ; dual-stack-servers [ port ] { ( [ port diff --git a/lib/isccc/ccmsg.c b/lib/isccc/ccmsg.c index 07a2d403ff..b3ce556efb 100644 --- a/lib/isccc/ccmsg.c +++ b/lib/isccc/ccmsg.c @@ -46,7 +46,7 @@ recv_message(isc_task_t *, isc_event_t *); static void recv_length(isc_task_t *task, isc_event_t *ev_in) { isc_socketevent_t *ev = (isc_socketevent_t *)ev_in; - isc_event_t *dev; + isc_event_t *dev = NULL; isccc_ccmsg_t *ccmsg = ev_in->ev_arg; isc_region_t region; isc_result_t result; @@ -101,10 +101,10 @@ send_and_free: static void recv_message(isc_task_t *task, isc_event_t *ev_in) { isc_socketevent_t *ev = (isc_socketevent_t *)ev_in; - isc_event_t *dev; + isc_event_t *dev = NULL; isccc_ccmsg_t *ccmsg = ev_in->ev_arg; - (void)task; + UNUSED(task); INSIST(VALID_CCMSG(ccmsg)); @@ -131,19 +131,17 @@ isccc_ccmsg_init(isc_mem_t *mctx, isc_socket_t *sock, isccc_ccmsg_t *ccmsg) { REQUIRE(sock != NULL); REQUIRE(ccmsg != NULL); - ccmsg->magic = CCMSG_MAGIC; - ccmsg->size = 0; - ccmsg->buffer.base = NULL; - ccmsg->buffer.length = 0; - ccmsg->maxsize = 4294967295U; /* Largest message possible. */ - ccmsg->mctx = mctx; - ccmsg->sock = sock; - ccmsg->task = NULL; /* None yet. */ - ccmsg->result = ISC_R_UNEXPECTED; /* None yet. */ - /* - * Should probably initialize the - *event here, but it can wait. - */ + *ccmsg = (isccc_ccmsg_t){ + .magic = CCMSG_MAGIC, + .maxsize = 0xffffffffU, /* Largest message possible. */ + .mctx = mctx, + .sock = sock, + .result = ISC_R_UNEXPECTED /* None yet. */ + }; + + /* + * Should probably initialize the event here, but it can wait. + */ } void @@ -197,21 +195,6 @@ isccc_ccmsg_cancelread(isccc_ccmsg_t *ccmsg) { isc_socket_cancel(ccmsg->sock, NULL, ISC_SOCKCANCEL_RECV); } -#if 0 -void -isccc_ccmsg_freebuffer(isccc_ccmsg_t*ccmsg) { - REQUIRE(VALID_CCMSG(ccmsg)); - - if (ccmsg->buffer.base == NULL) { - return; - } - - isc_mem_put(ccmsg->mctx,ccmsg->buffer.base,ccmsg->buffer.length); - ccmsg->buffer.base = NULL; - ccmsg->buffer.length = 0; -} -#endif /* if 0 */ - void isccc_ccmsg_invalidate(isccc_ccmsg_t *ccmsg) { REQUIRE(VALID_CCMSG(ccmsg));