The dns_{acl,aclenv}_create() can't fail, so change it to return void.
isc_netaddr_fromin6(&addr, &in6);
- result = dns_acl_create(named_g_mctx, 1, &acl);
- if (result != ISC_R_SUCCESS) {
- return (result);
- }
+ dns_acl_create(named_g_mctx, 1, &acl);
result = dns_iptable_addprefix(acl->iptable, &addr, 96, true);
if (result == ISC_R_SUCCESS) {
* for 'n' ACL elements. The elements are uninitialized and the
* length is 0.
*/
-isc_result_t
+void
dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target) {
- dns_acl_t *acl;
+ REQUIRE(target != NULL && *target == NULL);
+
+ dns_acl_t *acl = isc_mem_get(mctx, sizeof(*acl));
+ *acl = (dns_acl_t){
+ .refcount = 1,
+ .nextincache = ISC_LINK_INITIALIZER,
+ .elements = isc_mem_cget(mctx, n, sizeof(acl->elements[0])),
+ .alloc = n,
+ .ports_and_transports = ISC_LIST_INITIALIZER,
+ .magic = DNS_ACL_MAGIC,
+ };
- /*
- * Work around silly limitation of isc_mem_get().
- */
- if (n == 0) {
- n = 1;
- }
-
- acl = isc_mem_get(mctx, sizeof(*acl));
-
- acl->mctx = NULL;
isc_mem_attach(mctx, &acl->mctx);
- acl->name = NULL;
-
- isc_refcount_init(&acl->refcount, 1);
-
- dns_iptable_create(mctx, &acl->iptable);
-
- acl->elements = NULL;
- acl->alloc = 0;
- acl->length = 0;
- acl->has_negatives = false;
-
- ISC_LINK_INIT(acl, nextincache);
- /*
- * Must set magic early because we use dns_acl_detach() to clean up.
- */
- acl->magic = DNS_ACL_MAGIC;
-
- acl->elements = isc_mem_cget(mctx, n, sizeof(acl->elements[0]));
- acl->alloc = n;
- ISC_LIST_INIT(acl->ports_and_transports);
- acl->port_proto_entries = 0;
-
*target = acl;
- return (ISC_R_SUCCESS);
}
/*
isc_result_t result;
dns_acl_t *acl = NULL;
- result = dns_acl_create(mctx, 0, &acl);
- if (result != ISC_R_SUCCESS) {
- return (result);
- }
+ dns_acl_create(mctx, 0, &acl);
result = dns_iptable_addprefix(acl->iptable, NULL, 0, !neg);
if (result != ISC_R_SUCCESS) {
/*
* Initialize ACL environment, setting up localhost and localnets ACLs
*/
-isc_result_t
+void
dns_aclenv_create(isc_mem_t *mctx, dns_aclenv_t **envp) {
- isc_result_t result;
dns_aclenv_t *env = isc_mem_get(mctx, sizeof(*env));
- *env = (dns_aclenv_t){ 0 };
+ *env = (dns_aclenv_t){
+ .references = 1,
+ .magic = DNS_ACLENV_MAGIC,
+ };
isc_mem_attach(mctx, &env->mctx);
isc_refcount_init(&env->references, 1);
isc_rwlock_init(&env->rwlock);
- result = dns_acl_create(mctx, 0, &env->localhost);
- if (result != ISC_R_SUCCESS) {
- goto cleanup_rwlock;
- }
- result = dns_acl_create(mctx, 0, &env->localnets);
- if (result != ISC_R_SUCCESS) {
- goto cleanup_localhost;
- }
- env->match_mapped = false;
-#if defined(HAVE_GEOIP2)
- env->geoip = NULL;
-#endif /* if defined(HAVE_GEOIP2) */
-
- env->magic = DNS_ACLENV_MAGIC;
+ dns_acl_create(mctx, 0, &env->localhost);
+ dns_acl_create(mctx, 0, &env->localnets);
*envp = env;
-
- return (ISC_R_SUCCESS);
-
-cleanup_localhost:
- dns_acl_detach(&env->localhost);
-cleanup_rwlock:
- isc_rwlock_destroy(&env->rwlock);
- isc_mem_putanddetach(&env->mctx, env, sizeof(*env));
- return (result);
}
void
ISC_LANG_BEGINDECLS
-isc_result_t
+void
dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target);
/*%<
* Create a new ACL, including an IP table and an array with room
* permitted by 'acl' in environment 'aclenv'.
*/
-isc_result_t
+void
dns_aclenv_create(isc_mem_t *mctx, dns_aclenv_t **envp);
/*%<
* Create ACL environment, setting up localhost and localnets ACLs
goto cleanup_order;
}
- result = dns_aclenv_create(view->mctx, &view->aclenv);
- if (result != ISC_R_SUCCESS) {
- goto cleanup_peerlist;
- }
+ dns_aclenv_create(view->mctx, &view->aclenv);
dns_nametree_create(view->mctx, DNS_NAMETREE_COUNT, "sfd", &view->sfd);
return (ISC_R_SUCCESS);
-cleanup_peerlist:
- if (view->peers != NULL) {
- dns_peerlist_detach(&view->peers);
- }
-
cleanup_order:
if (view->order != NULL) {
dns_order_detach(&view->order);
nelem = cfg_list_length(caml, false);
}
- result = dns_acl_create(mctx, nelem, &dacl);
- if (result != ISC_R_SUCCESS) {
- return (result);
- }
+ dns_acl_create(mctx, nelem, &dacl);
}
if (is_tuple) {
iptab = dacl->iptable;
if (nest_level != 0) {
- result = dns_acl_create(mctx,
- cfg_list_length(ce, false),
- &de->nestedacl);
- if (result != ISC_R_SUCCESS) {
- goto cleanup;
- }
+ dns_acl_create(mctx, cfg_list_length(ce, false),
+ &de->nestedacl);
iptab = de->nestedacl->iptable;
}
}
ns_listenlist_attach(mgr->listenon4, &mgr->listenon6);
- result = dns_aclenv_create(mctx, &mgr->aclenv);
- if (result != ISC_R_SUCCESS) {
- goto cleanup_listenon;
- }
+ dns_aclenv_create(mctx, &mgr->aclenv);
#if defined(HAVE_GEOIP2)
mgr->aclenv->geoip = geoip;
#else /* if defined(HAVE_GEOIP2) */
return (ISC_R_SUCCESS);
-cleanup_listenon:
- ns_listenlist_detach(&mgr->listenon4);
- ns_listenlist_detach(&mgr->listenon6);
cleanup_lock:
isc_mutex_destroy(&mgr->lock);
ns_server_detach(&mgr->sctx);
return (result);
}
- result = dns_acl_create(mgr->mctx, 0, &localhost);
- if (result != ISC_R_SUCCESS) {
- goto cleanup_iter;
- }
- result = dns_acl_create(mgr->mctx, 0, &localnets);
- if (result != ISC_R_SUCCESS) {
- goto cleanup_localhost;
- }
+ dns_acl_create(mgr->mctx, 0, &localhost);
+ dns_acl_create(mgr->mctx, 0, &localnets);
clearlistenon(mgr);
dns_aclenv_set(mgr->aclenv, localhost, localnets);
- /* cleanup_localnets: */
dns_acl_detach(&localnets);
-
-cleanup_localhost:
dns_acl_detach(&localhost);
-cleanup_iter:
isc_interfaceiter_destroy(&iter);
return (result);
}
result = dns_acl_none(mctx, &none);
assert_int_equal(result, ISC_R_SUCCESS);
- result = dns_acl_create(mctx, 1, ¬none);
- assert_int_equal(result, ISC_R_SUCCESS);
+ dns_acl_create(mctx, 1, ¬none);
- result = dns_acl_create(mctx, 1, ¬any);
- assert_int_equal(result, ISC_R_SUCCESS);
+ dns_acl_create(mctx, 1, ¬any);
result = dns_acl_merge(notnone, none, false);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(result, ISC_R_SUCCESS);
#if defined(HAVE_GEOIP2)
- result = dns_acl_create(mctx, 1, &geoip);
- assert_int_equal(result, ISC_R_SUCCESS);
+ dns_acl_create(mctx, 1, &geoip);
de = geoip->elements;
assert_non_null(de);
de->node_num = dns_acl_node_count(geoip);
geoip->length++;
- result = dns_acl_create(mctx, 1, ¬geoip);
- assert_int_equal(result, ISC_R_SUCCESS);
+ dns_acl_create(mctx, 1, ¬geoip);
result = dns_acl_merge(notgeoip, geoip, false);
assert_int_equal(result, ISC_R_SUCCESS);