Compare commits

..
29 changed files with 449 additions and 636 deletions
+58 -63
View File
@@ -162,7 +162,7 @@ stages:
expire_in: '1 week'
when: on_failure
sid:amd64:precheck:
precheck:debian:sid:amd64:
<<: *debian_sid_amd64_image
stage: precheck
script:
@@ -182,16 +182,11 @@ sid:amd64:precheck:
expire_in: '1 week'
when: on_failure
🐞:sid:amd64:precheck:
<<: *debian_sid_amd64_image
stage: precheck
script: util/check-cocci
docs:sid:amd64:
docs:debian:sid:amd64:
<<: *debian_sid_amd64_image
stage: test
dependencies:
- sid:amd64:build
- build:debian:sid:amd64
script:
- make -C doc/misc docbook
- make -C doc/arm Bv9ARM.html
@@ -200,7 +195,7 @@ docs:sid:amd64:
- doc/arm/
expire_in: '1 month'
docs:push:
push:docs:
<<: *debian_sid_amd64_image
stage: push
dependencies: []
@@ -210,15 +205,15 @@ docs:push:
- master@isc-projects/bind9
- /^v9_.*$/@isc-projects/bind9
#jessie:amd64:build:
#build:debian:jessie:amd64:
# <<: *debian_jessie_amd64_image
# <<: *build_job
#
#build:jessie:i386:
#build:debian:jessie:i386:
# <<: *debian_jessie_i386_image
# <<: *build_job
#
#build:stretch:amd64:
#build:debian:stretch:amd64:
# <<: *debian_stretch_amd64_image
# <<: *build_job
#
@@ -234,7 +229,7 @@ docs:push:
# <<: *ubuntu_xenial_i386_image
# <<: *build_job
centos6:amd64:build:
build:centos:centos6:amd64:
variables:
CC: gcc
CFLAGS: "-Wall -Wextra -O2 -g"
@@ -242,7 +237,7 @@ centos6:amd64:build:
<<: *centos_centos6_amd64_image
<<: *build_job
centos7:amd64:build:
build:centos:centos7:amd64:
variables:
CC: gcc
CFLAGS: "-Wall -Wextra -O2 -g"
@@ -250,14 +245,14 @@ centos7:amd64:build:
<<: *centos_centos7_amd64_image
<<: *build_job
clang:stretch:amd64:build:
build:clang:debian:stretch:amd64:
variables:
CC: clang
CFLAGS: "-Wall -Wextra -Wenum-conversion -O2 -g"
<<: *debian_stretch_amd64_image
<<: *build_job
jessie:amd64:build:
build:debian:jessie:amd64:
variables:
CC: gcc
CFLAGS: "-Wall -Wextra -O2 -g"
@@ -265,14 +260,14 @@ jessie:amd64:build:
<<: *debian_jessie_amd64_image
<<: *build_job
stretch:amd64:build:
build:debian:stretch:amd64:
variables:
CC: gcc
CFLAGS: "-Wall -Wextra -O2 -g"
<<: *debian_stretch_amd64_image
<<: *build_job
sid:amd64:build:
build:debian:sid:amd64:
variables:
CC: gcc
CFLAGS: "-Wall -Wextra -O2 -g"
@@ -280,7 +275,7 @@ sid:amd64:build:
<<: *debian_sid_amd64_image
<<: *build_job
asan:sid:amd64:build:
build:asan:debian:sid:amd64:
variables:
CC: gcc
CFLAGS: "-Wall -Wextra -O2 -g -fsanitize=address,undefined -DISC_MEM_USE_INTERNAL_MALLOC=0"
@@ -289,14 +284,14 @@ asan:sid:amd64:build:
<<: *debian_sid_amd64_image
<<: *build_job
clang:stretch:i386:build:
build:clang:debian:stretch:i386:
variables:
CC: clang
CFLAGS: "-Wall -Wextra -Wenum-conversion -O2 -g"
<<: *debian_stretch_i386_image
<<: *build_job
sid:i386:build:
build:debian:sid:i386:
variables:
CC: gcc
CFLAGS: "-Wall -Wextra -O2 -g"
@@ -304,103 +299,103 @@ sid:i386:build:
<<: *debian_sid_i386_image
<<: *build_job
unit:centos6:amd64:
unittest:centos:centos6:amd64:
<<: *centos_centos6_amd64_image
<<: *unit_test_job
dependencies:
- centos6:amd64:build
- build:centos:centos6:amd64
unit:centos7:amd64:
unittest:centos:centos7:amd64:
<<: *centos_centos7_amd64_image
<<: *unit_test_job
dependencies:
- centos7:amd64:build
- build:centos:centos7:amd64
unit:jessie:amd64:
unittest:debian:jessie:amd64:
<<: *debian_jessie_amd64_image
<<: *unit_test_job
dependencies:
- jessie:amd64:build
- build:debian:jessie:amd64
unit:stretch:amd64:
unittest:debian:stretch:amd64:
<<: *debian_stretch_amd64_image
<<: *unit_test_job
dependencies:
- stretch:amd64:build
- build:debian:stretch:amd64
unit:sid:amd64:
unittest:debian:sid:amd64:
<<: *debian_sid_amd64_image
<<: *unit_test_job
dependencies:
- sid:amd64:build
- build:debian:sid:amd64
unit:asan:sid:amd64:
unittest:asan:debian:sid:amd64:
<<: *debian_sid_amd64_image
<<: *unit_test_job
dependencies:
- asan:sid:amd64:build
- build:asan:debian:sid:amd64
unit:clang:stretch:amd64:
unittest:clang:debian:stretch:amd64:
<<: *debian_stretch_amd64_image
<<: *unit_test_job
dependencies:
- clang:stretch:amd64:build
- build:clang:debian:stretch:amd64
unit:sid:i386:
unittest:debian:sid:i386:
<<: *debian_sid_i386_image
<<: *unit_test_job
dependencies:
- sid:i386:build
- build:debian:sid:i386
system:centos6:amd64:
systemtest:centos:centos6:amd64:
<<: *centos_centos6_amd64_image
<<: *system_test_job
dependencies:
- centos6:amd64:build
- build:centos:centos6:amd64
system:centos7:amd64:
systemtest:centos:centos7:amd64:
<<: *centos_centos7_amd64_image
<<: *system_test_job
dependencies:
- centos7:amd64:build
- build:centos:centos7:amd64
system:jessie:amd64:
systemtest:debian:jessie:amd64:
<<: *debian_jessie_amd64_image
<<: *system_test_job
dependencies:
- jessie:amd64:build
- build:debian:jessie:amd64
system:stretch:amd64:
systemtest:debian:stretch:amd64:
<<: *debian_stretch_amd64_image
<<: *system_test_job
dependencies:
- stretch:amd64:build
- build:debian:stretch:amd64
system:sid:amd64:
systemtest:debian:sid:amd64:
<<: *debian_sid_amd64_image
<<: *system_test_job
dependencies:
- sid:amd64:build
- build:debian:sid:amd64
system:asan:sid:amd64:
systemtest:asan:debian:sid:amd64:
<<: *debian_sid_amd64_image
<<: *system_test_job
dependencies:
- asan:sid:amd64:build
- build:asan:debian:sid:amd64
system:sid:i386:
systemtest:debian:sid:i386:
<<: *debian_sid_i386_image
<<: *system_test_job
dependencies:
- sid:i386:build
- build:debian:sid:i386
install:sid:amd64:
install:debian:sid:amd64:
<<: *debian_sid_amd64_image
<<: *install_test_job
dependencies:
- sid:amd64:build
- build:debian:sid:amd64
pkcs11:sid:amd64:build:
pkcs11:build:debian:sid:amd64:
variables:
CC: gcc
CFLAGS: "-Wall -Wextra -O2 -g"
@@ -408,19 +403,19 @@ pkcs11:sid:amd64:build:
<<: *debian_sid_amd64_image
<<: *build_job
pkcs11:unit:sid:amd64:
pkcs11:unittest:debian:sid:amd64:
<<: *debian_sid_amd64_image
<<: *unit_test_job
dependencies:
- pkcs11:sid:amd64:build
- pkcs11:build:debian:sid:amd64
pkcs11:system:sid:amd64:
pkcs11:systemtest:debian:sid:amd64:
<<: *debian_sid_amd64_image
<<: *system_test_job
dependencies:
- pkcs11:sid:amd64:build
- pkcs11:build:debian:sid:amd64
noassert:sid:amd64:build:
noassert:build:debian:sid:amd64:
variables:
CC: gcc
CFLAGS: "-Wall -Wextra -O2 -g -DISC_CHECK_NONE=1"
@@ -428,14 +423,14 @@ noassert:sid:amd64:build:
<<: *debian_sid_amd64_image
<<: *build_job
noassert:unit:sid:amd64:
noassert:unittest:debian:sid:amd64:
<<: *debian_sid_amd64_image
<<: *unit_test_job
dependencies:
- noassert:sid:amd64:build
- noassert:build:debian:sid:amd64
noassert:system:sid:amd64:
noassert:systemtest:debian:sid:amd64:
<<: *debian_sid_amd64_image
<<: *system_test_job
dependencies:
- noassert:sid:amd64:build
- noassert:build:debian:sid:amd64
+1 -3
View File
@@ -1,6 +1,4 @@
5100. [func] Pin resolver tasks to specific task queues. [GL !1117]
5099. [func] Failed mutex and conditional creations are always
5099. [func] Failed mutex and conditional creations are always
fatal. [GL #674]
--- 9.13.4 released ---
+7 -8
View File
@@ -9351,11 +9351,7 @@ load_zones(named_server_t *server, bool init, bool reconfig) {
* zones.
*/
isc_refcount_increment(&zl->refs);
result = dns_view_asyncload(view, reconfig, view_loaded, zl);
if (result != ISC_R_SUCCESS) {
isc_refcount_decrement(&zl->refs);
goto cleanup;
}
CHECK(dns_view_asyncload(view, reconfig, view_loaded, zl));
}
cleanup:
@@ -14420,6 +14416,7 @@ named_server_nta(named_server_t *server, isc_lex_t *lex,
bool ttlset = false, excl = false, viewfound = false;
dns_rdataclass_t rdclass = dns_rdataclass_in;
bool first = true;
bool is_option = true;
UNUSED(force);
@@ -14439,8 +14436,10 @@ named_server_nta(named_server_t *server, isc_lex_t *lex,
return (ISC_R_UNEXPECTEDEND);
}
if (strcmp(ptr, "--") == 0) {
break;
if (!is_option) {
nametext = ptr;
} else if (strcmp(ptr, "--") == 0) {
is_option = false;
} else if (argcheck(ptr, "dump")) {
dump = true;
} else if (argcheck(ptr, "remove")) {
@@ -14527,7 +14526,7 @@ named_server_nta(named_server_t *server, isc_lex_t *lex,
CHECK(ISC_R_FAILURE);
}
/* Get the NTA name if not found above. */
/* Get the NTA name. */
if (nametext == NULL) {
nametext = next_token(lex, text);
}
+5
View File
@@ -359,6 +359,7 @@ main(int argc, char *argv[]) {
dbinfo *dbi;
dns_dbversion_t *version;
const dns_name_t *origin;
size_t memory_quota = 0;
dns_trust_t trust = 0;
unsigned int addopts;
isc_log_t *lctx = NULL;
@@ -410,6 +411,10 @@ main(int argc, char *argv[]) {
case 'P':
pause_every = atoi(isc_commandline_argument);
break;
case 'Q':
memory_quota = atoi(isc_commandline_argument);
isc_mem_setquota(mctx, memory_quota);
break;
case 't':
type = atoi(isc_commandline_argument);
break;
-1
View File
@@ -1 +0,0 @@
/*.patch
-6
View File
@@ -1,6 +0,0 @@
@@
@@
INSIST(0);
+ ISC_UNREACHABLE();
... when != ISC_UNREACHABLE();
Vendored
+8 -1
View File
@@ -20332,7 +20332,7 @@ else
fi
;; #(
*-freebsd*|*-openbsd*|*-netbsd*) :
*-freebsd*|*-openbsd*) :
LDFLAGS="${LDFLAGS} -Wl,-E"
SO_CFLAGS="-fpic"
@@ -20348,6 +20348,13 @@ else
fi
;; #(
*-netbsd*) :
SO_CFLAGS="-fpic"
SO_LDFLAGS="-Bshareable -x"
SO_LD="ld"
SO_STRIP="sed -e s/-Wl,//g"
;; #(
*-solaris*) :
SO_CFLAGS="-KPIC"
+7 -1
View File
@@ -2697,7 +2697,7 @@ AS_IF([test "$with_dlopen" = "yes"],
SO_LD="${CC}"
])
],
[*-freebsd*|*-openbsd*|*-netbsd*],[
[*-freebsd*|*-openbsd*],[
LDFLAGS="${LDFLAGS} -Wl,-E"
SO_CFLAGS="-fpic"
AS_IF([test "$use_libtool" = "yes"],[
@@ -2708,6 +2708,12 @@ AS_IF([test "$with_dlopen" = "yes"],
SO_LD="${CC}"
])
],
[*-netbsd*],[
SO_CFLAGS="-fpic"
SO_LDFLAGS="-Bshareable -x"
SO_LD="ld"
SO_STRIP="sed -e s/-Wl,//g"
],
[*-solaris*],[
SO_CFLAGS="-KPIC"
SO_LDFLAGS="-G -z text"
+1 -1
View File
@@ -2468,7 +2468,7 @@ dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_socket_t *sock,
disp->ntasks = 1;
disp->task[0] = NULL;
result = isc_task_create(taskmgr, 50, &disp->task[0]);
result = isc_task_create(taskmgr, 0, &disp->task[0]);
if (result != ISC_R_SUCCESS)
goto kill_socket;
+1 -1
View File
@@ -810,7 +810,7 @@ dns_geoip_match(const isc_netaddr_t *reqaddr,
default:
INSIST(0);
ISC_UNREACHABLE();
ISC_UNREACHABLE()
}
return (false);
+3 -8
View File
@@ -4382,8 +4382,8 @@ fctx_shutdown(fetchctx_t *fctx) {
*/
if (fctx->state != fetchstate_init) {
cevent = &fctx->control_event;
isc_task_sendto(fctx->res->buckets[fctx->bucketnum].task,
&cevent, fctx->bucketnum);
isc_task_send(fctx->res->buckets[fctx->bucketnum].task,
&cevent);
}
}
@@ -9924,12 +9924,7 @@ dns_resolver_create(dns_view_t *view,
isc_mutex_init(&res->buckets[i].lock);
res->buckets[i].task = NULL;
/*
* Since we have a pool of tasks we bind them to task queues
* to spread the load evenly
*/
result = isc_task_create_bound(taskmgr, 0,
&res->buckets[i].task, i);
result = isc_task_create(taskmgr, 0, &res->buckets[i].task);
if (result != ISC_R_SUCCESS) {
isc_mutex_destroy(&res->buckets[i].lock);
goto cleanup_buckets;
+3 -3
View File
@@ -334,7 +334,7 @@ make_addr_set(dns_rpz_addr_zbits_t *tgt_set, dns_rpz_zbits_t zbits,
break;
default:
INSIST(0);
ISC_UNREACHABLE();
break;
}
}
@@ -353,7 +353,7 @@ make_nm_set(dns_rpz_nm_zbits_t *tgt_set,
break;
default:
INSIST(0);
ISC_UNREACHABLE();
break;
}
}
@@ -2564,7 +2564,7 @@ dns_rpz_find_ip(dns_rpz_zones_t *rpzs, dns_rpz_type_t rpz_type,
break;
default:
INSIST(0);
ISC_UNREACHABLE();
break;
}
result = ip2name(&found->ip, found->prefix, dns_rootname, ip_name);
RWUNLOCK(&rpzs->search_lock, isc_rwlocktype_read);
+4 -1
View File
@@ -606,6 +606,7 @@ getlabel_test(void **state) {
dns_fixedname_t f1, f2;
dns_name_t *n1, *n2;
dns_label_t l1, l2;
unsigned char *p1, *p2;
unsigned int j;
n1 = dns_fixedname_initname(&f1);
@@ -622,8 +623,10 @@ getlabel_test(void **state) {
dns_name_getlabel(n2, testcases[i].pos2, &l2);
assert_int_equal(l1.length, l2.length);
p1 = l1.base;
p2 = l2.base;
for (j = 0; j < l1.length; j++) {
assert_int_equal(l1.base[j], l2.base[j]);
assert_int_equal(*p1++, *p2++);
}
}
}
+12
View File
@@ -333,6 +333,18 @@ isc_mem_setdestroycheck(isc_mem_t *mctx,
* destroyed and abort the program if any are present.
*/
/*@{*/
void
isc_mem_setquota(isc_mem_t *, size_t);
size_t
isc_mem_getquota(isc_mem_t *);
/*%<
* Set/get the memory quota of 'mctx'. This is a hard limit
* on the amount of memory that may be allocated from mctx;
* if it is exceeded, allocations will fail.
*/
/*@}*/
size_t
isc_mem_inuse(isc_mem_t *mctx);
/*%<
-9
View File
@@ -89,12 +89,6 @@ isc_quota_release(isc_quota_t *quota);
* Release one unit of quota.
*/
isc_result_t
isc_quota_release_verbose(isc_quota_t *quota);
/*%<
* Release one unit of quota and return the result.
*/
isc_result_t
isc_quota_attach(isc_quota_t *quota, isc_quota_t **p);
/*%<
@@ -109,9 +103,6 @@ isc_quota_detach(isc_quota_t **p);
* quota.
*/
isc_result_t
isc_quota_detach_verbose(isc_quota_t **p);
ISC_LANG_ENDDECLS
#endif /* ISC_QUOTA_H */
-9
View File
@@ -1038,15 +1038,6 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr, json_object *stats);
typedef isc_result_t
(*isc_socketmgrcreatefunc_t)(isc_mem_t *mctx, isc_socketmgr_t **managerp);
typedef isc_result_t
(*isc_socketevent_factory_t)(void* arg, isc_socketevent_t **ret);
isc_result_t
isc_socket_udpsubscribe(isc_socket_t *sock, isc_socketevent_factory_t evf, void* arg);
void
isc_socket_udpsubscription_toggle(isc_socket_t *usock, bool on);
ISC_LANG_ENDDECLS
#endif /* ISC_SOCKET_H */
-4
View File
@@ -136,10 +136,6 @@ struct isc_task {
isc_result_t
isc_task_create(isc_taskmgr_t *manager, unsigned int quantum,
isc_task_t **taskp);
isc_result_t
isc_task_create_bound(isc_taskmgr_t *manager, unsigned int quantum,
isc_task_t **taskp, int threadid);
/*%<
* Create a task.
*
+111 -12
View File
@@ -135,6 +135,7 @@ struct isc__mem {
isc_refcount_t references;
char name[16];
void * tag;
size_t quota;
size_t total;
size_t inuse;
size_t maxinuse;
@@ -164,6 +165,7 @@ struct isc__mem {
size_t debuglistcnt;
#endif
unsigned int memalloc_failures;
ISC_LINK(isc__mem_t) link;
};
@@ -354,16 +356,27 @@ more_basic_blocks(isc__mem_t *ctx) {
unsigned char *first, *last;
unsigned char **table;
unsigned int table_size;
size_t increment;
int i;
/* Require: we hold the context lock. */
/*
* Did we hit the quota for this context?
*/
increment = NUM_BASIC_BLOCKS * ctx->mem_target;
if (ctx->quota != 0U && ctx->total + increment > ctx->quota)
return (false);
INSIST(ctx->basic_table_count <= ctx->basic_table_size);
if (ctx->basic_table_count == ctx->basic_table_size) {
table_size = ctx->basic_table_size + TABLE_INCREMENT;
table = (ctx->memalloc)(ctx->arg,
table_size * sizeof(unsigned char *));
RUNTIME_CHECK(table != NULL);
if (table == NULL) {
ctx->memalloc_failures++;
return (false);
}
ctx->malloced += table_size * sizeof(unsigned char *);
if (ctx->malloced > ctx->maxmalloced)
ctx->maxmalloced = ctx->malloced;
@@ -380,8 +393,11 @@ more_basic_blocks(isc__mem_t *ctx) {
}
tmp = (ctx->memalloc)(ctx->arg, NUM_BASIC_BLOCKS * ctx->mem_target);
RUNTIME_CHECK(tmp != NULL);
ctx->total += NUM_BASIC_BLOCKS * ctx->mem_target;;
if (tmp == NULL) {
ctx->memalloc_failures++;
return (false);
}
ctx->total += increment;
ctx->basic_table[ctx->basic_table_count] = tmp;
ctx->basic_table_count++;
ctx->malloced += NUM_BASIC_BLOCKS * ctx->mem_target;
@@ -482,8 +498,15 @@ mem_getunlocked(isc__mem_t *ctx, size_t size) {
/*
* memget() was called on something beyond our upper limit.
*/
if (ctx->quota != 0U && ctx->total + size > ctx->quota) {
ret = NULL;
goto done;
}
ret = (ctx->memalloc)(ctx->arg, size);
RUNTIME_CHECK(ret != NULL);
if (ret == NULL) {
ctx->memalloc_failures++;
goto done;
}
ctx->total += size;
ctx->inuse += size;
ctx->stats[ctx->max_size].gets++;
@@ -606,7 +629,8 @@ mem_get(isc__mem_t *ctx, size_t size) {
size += 1;
#endif
ret = (ctx->memalloc)(ctx->arg, size);
RUNTIME_CHECK(ret != NULL);
if (ret == NULL)
ctx->memalloc_failures++;
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
if (ISC_LIKELY(ret != NULL))
@@ -742,6 +766,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
isc_mem_t **ctxp, unsigned int flags)
{
isc__mem_t *ctx;
isc_result_t result;
REQUIRE(ctxp != NULL && *ctxp == NULL);
REQUIRE(memalloc != NULL);
@@ -753,7 +778,9 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
ctx = (memalloc)(arg, sizeof(*ctx));
RUNTIME_CHECK(ctx != NULL);
if (ctx == NULL) {
return (ISC_R_NOMEMORY);
}
if ((flags & ISC_MEMFLAG_NOLOCK) == 0) {
isc_mutex_init(&ctx->lock);
@@ -767,6 +794,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
isc_refcount_init(&ctx->references, 1);
memset(ctx->name, 0, sizeof(ctx->name));
ctx->tag = NULL;
ctx->quota = 0;
ctx->total = 0;
ctx->inuse = 0;
ctx->maxinuse = 0;
@@ -802,8 +830,10 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
ctx->stats = (memalloc)(arg,
(ctx->max_size+1) * sizeof(struct stats));
RUNTIME_CHECK(ctx->stats != NULL);
if (ctx->stats == NULL) {
result = ISC_R_NOMEMORY;
goto error;
}
memset(ctx->stats, 0, (ctx->max_size + 1) * sizeof(struct stats));
ctx->malloced += (ctx->max_size+1) * sizeof(struct stats);
ctx->maxmalloced += (ctx->max_size+1) * sizeof(struct stats);
@@ -815,7 +845,10 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
ctx->mem_target = target_size;
ctx->freelists = (memalloc)(arg, ctx->max_size *
sizeof(element *));
RUNTIME_CHECK(ctx->freelists != NULL);
if (ctx->freelists == NULL) {
result = ISC_R_NOMEMORY;
goto error;
}
memset(ctx->freelists, 0,
ctx->max_size * sizeof(element *));
ctx->malloced += ctx->max_size * sizeof(element *);
@@ -828,7 +861,10 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
ctx->debuglist = (memalloc)(arg, (DEBUG_TABLE_COUNT *
sizeof(debuglist_t)));
RUNTIME_CHECK(ctx->debuglist != NULL);
if (ctx->debuglist == NULL) {
result = ISC_R_NOMEMORY;
goto error;
}
for (i = 0; i < DEBUG_TABLE_COUNT; i++)
ISC_LIST_INIT(ctx->debuglist[i]);
ctx->malloced += DEBUG_TABLE_COUNT * sizeof(debuglist_t);
@@ -836,6 +872,8 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
}
#endif
ctx->memalloc_failures = 0;
LOCK(&contextslock);
ISC_LIST_INITANDAPPEND(contexts, ctx, link);
UNLOCK(&contextslock);
@@ -843,6 +881,23 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
*ctxp = (isc_mem_t *)ctx;
return (ISC_R_SUCCESS);
error:
if (ctx != NULL) {
if (ctx->stats != NULL)
(memfree)(arg, ctx->stats);
if (ctx->freelists != NULL)
(memfree)(arg, ctx->freelists);
#if ISC_MEM_TRACKLINES
if (ctx->debuglist != NULL)
(ctx->memfree)(ctx->arg, ctx->debuglist);
#endif /* ISC_MEM_TRACKLINES */
if ((ctx->flags & ISC_MEMFLAG_NOLOCK) == 0)
isc_mutex_destroy(&ctx->lock);
(memfree)(arg, ctx);
}
return (result);
}
static void
@@ -1451,6 +1506,37 @@ isc_mem_setdestroycheck(isc_mem_t *ctx0, bool flag) {
MCTXUNLOCK(ctx, &ctx->lock);
}
/*
* Quotas
*/
void
isc_mem_setquota(isc_mem_t *ctx0, size_t quota) {
isc__mem_t *ctx = (isc__mem_t *)ctx0;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
ctx->quota = quota;
MCTXUNLOCK(ctx, &ctx->lock);
}
size_t
isc_mem_getquota(isc_mem_t *ctx0) {
isc__mem_t *ctx = (isc__mem_t *)ctx0;
size_t quota;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
quota = ctx->quota;
MCTXUNLOCK(ctx, &ctx->lock);
return (quota);
}
size_t
isc_mem_inuse(isc_mem_t *ctx0) {
isc__mem_t *ctx = (isc__mem_t *)ctx0;
@@ -1598,7 +1684,8 @@ isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) {
* well, attach to the memory context.
*/
mpctx = isc_mem_get((isc_mem_t *)mctx, sizeof(isc__mempool_t));
RUNTIME_CHECK(mpctx != NULL);
if (mpctx == NULL)
return (ISC_R_NOMEMORY);
mpctx->common.impmagic = MEMPOOL_MAGIC;
mpctx->common.magic = ISCAPI_MPOOL_MAGIC;
@@ -2242,10 +2329,16 @@ isc_mem_renderxml(xmlTextWriterPtr writer) {
#endif /* HAVE_LIBXML2 */
#ifdef HAVE_JSON
#define CHECKMEM(m) RUNTIME_CHECK(m != NULL)
#define CHECKMEM(m) do { \
if (m == NULL) { \
result = ISC_R_NOMEMORY;\
goto error;\
} \
} while(0)
static isc_result_t
json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) {
isc_result_t result = ISC_R_FAILURE;
json_object *ctxobj, *obj;
char buf[1024];
@@ -2337,6 +2430,12 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) {
MCTXUNLOCK(ctx, &ctx->lock);
json_object_array_add(array, ctxobj);
return (ISC_R_SUCCESS);
error:
MCTXUNLOCK(ctx, &ctx->lock);
if (ctxobj != NULL)
json_object_put(ctxobj);
return (result);
}
isc_result_t
-23
View File
@@ -71,10 +71,6 @@ isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg,
return (ISC_R_SUCCESS);
}
#ifdef __NetBSD__
#define pthread_setconcurrency(a) (void) a/* nothing */
#endif
void
isc_thread_setconcurrency(unsigned int level) {
(void)pthread_setconcurrency(level);
@@ -87,11 +83,7 @@ isc_thread_setname(isc_thread_t thread, const char *name) {
* macOS has pthread_setname_np but only works on the
* current thread so it's not used here
*/
#if defined(__NetBSD__)
(void)pthread_setname_np(thread, name, NULL);
#else
(void)pthread_setname_np(thread, name);
#endif
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
(void)pthread_set_name_np(thread, name);
#else
@@ -123,20 +115,6 @@ isc_thread_setaffinity(int cpu) {
return (ISC_R_FAILURE);
}
#elif defined(HAVE_PTHREAD_SETAFFINITY_NP)
#if defined(__NetBSD__)
cpuset_t *cset;
cset = cpuset_create();
if (cset == NULL)
return (ISC_R_FAILURE);
cpuset_set(cpu, cset);
if (pthread_setaffinity_np(pthread_self(),
cpuset_size(cset), cset) != 0)
{
cpuset_destroy(cset);
return (ISC_R_FAILURE);
}
cpuset_destroy(cset);
#else /* linux? */
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(cpu, &set);
@@ -145,7 +123,6 @@ isc_thread_setaffinity(int cpu) {
{
return (ISC_R_FAILURE);
}
#endif /* __NetBSD__ */
#elif defined(HAVE_PROCESSOR_BIND)
if (processor_bind(P_LWPID, P_MYID, cpu, NULL) != 0) {
return (ISC_R_FAILURE);
+4 -36
View File
@@ -55,15 +55,13 @@ isc_quota_reserve(isc_quota_t *quota) {
isc_result_t result;
LOCK(&quota->lock);
if (quota->max == 0 || quota->used < quota->max) {
if (quota->soft == 0 || quota->used < quota->soft) {
if (quota->soft == 0 || quota->used < quota->soft)
result = ISC_R_SUCCESS;
} else {
else
result = ISC_R_SOFTQUOTA;
}
quota->used++;
} else {
} else
result = ISC_R_QUOTA;
}
UNLOCK(&quota->lock);
return (result);
}
@@ -76,34 +74,14 @@ isc_quota_release(isc_quota_t *quota) {
UNLOCK(&quota->lock);
}
isc_result_t
isc_quota_release_verbose(isc_quota_t *quota) {
isc_result_t result;
LOCK(&quota->lock);
INSIST(quota->used > 0);
quota->used--;
if (quota->max == 0 || quota->used <= quota->max) {
if (quota->soft == 0 || quota->used <= quota->soft) {
result = ISC_R_SUCCESS;
} else {
result = ISC_R_SOFTQUOTA;
}
} else {
result = ISC_R_QUOTA;
}
UNLOCK(&quota->lock);
return (result);
}
isc_result_t
isc_quota_attach(isc_quota_t *quota, isc_quota_t **p)
{
isc_result_t result;
INSIST(p != NULL && *p == NULL);
result = isc_quota_reserve(quota);
if (result == ISC_R_SUCCESS || result == ISC_R_SOFTQUOTA) {
if (result == ISC_R_SUCCESS || result == ISC_R_SOFTQUOTA)
*p = quota;
}
return (result);
}
@@ -114,13 +92,3 @@ isc_quota_detach(isc_quota_t **p)
isc_quota_release(*p);
*p = NULL;
}
isc_result_t
isc_quota_detach_verbose(isc_quota_t **p)
{
isc_result_t result;
INSIST(p != NULL && *p != NULL);
result = isc_quota_release_verbose(*p);
*p = NULL;
return (result);
}
+13 -49
View File
@@ -49,10 +49,6 @@
* state it will stay on the runner it's currently on, if a task is in idle
* state it can be woken up on a specific runner with isc_task_sendto - that
* helps with data locality on CPU.
*
* To make load even some tasks (from task pools) are bound to specific
* queues using isc_task_create_bound. This way load balancing between
* CPUs/queues happens on the higher layer.
*/
#ifdef ISC_TASK_TRACE
@@ -108,7 +104,6 @@ struct isc__task {
char name[16];
void * tag;
unsigned int threadid;
bool bound;
/* Locked by task manager lock. */
LINK(isc__task_t) link;
LINK(isc__task_t) ready_link;
@@ -247,14 +242,7 @@ task_finished(isc__task_t *task) {
isc_result_t
isc_task_create(isc_taskmgr_t *manager0, unsigned int quantum,
isc_task_t **taskp)
{
return (isc_task_create_bound(manager0, quantum, taskp, -1));
}
isc_result_t
isc_task_create_bound(isc_taskmgr_t *manager0, unsigned int quantum,
isc_task_t **taskp, int threadid)
isc_task_t **taskp)
{
isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0;
isc__task_t *task;
@@ -268,31 +256,15 @@ isc_task_create_bound(isc_taskmgr_t *manager0, unsigned int quantum,
return (ISC_R_NOMEMORY);
XTRACE("isc_task_create");
task->manager = manager;
if (threadid == -1) {
/*
* Task is not pinned to a queue, it's threadid will be
* choosen when first task will be sent to it - either
* randomly or specified by isc_task_sendto.
*/
task->bound = false;
task->threadid = 0;
} else {
/*
* Task is pinned to a queue, it'll always be run
* by a specific thread.
*/
task->bound = true;
task->threadid = threadid % manager->workers;
}
task->threadid = isc_random_uniform(manager->workers);
isc_mutex_init(&task->lock);
task->state = task_state_idle;
task->references = 1;
INIT_LIST(task->events);
INIT_LIST(task->on_shutdown);
task->nevents = 0;
task->quantum = (quantum > 0) ? quantum : manager->default_quantum;
task->quantum = quantum;
task->flags = 0;
task->now = 0;
isc_time_settoepoch(&task->tnow);
@@ -305,10 +277,11 @@ isc_task_create_bound(isc_taskmgr_t *manager0, unsigned int quantum,
exiting = false;
LOCK(&manager->lock);
if (!manager->exiting) {
if (task->quantum == 0)
task->quantum = manager->default_quantum;
APPEND(manager->tasks, task, link);
} else {
} else
exiting = true;
}
UNLOCK(&manager->lock);
if (exiting) {
@@ -514,14 +487,9 @@ isc_task_sendto(isc_task_t *task0, isc_event_t **eventp, int c) {
REQUIRE(VALID_TASK(task));
XTRACE("isc_task_send");
/* If task is bound ignore provided cpu. */
if (task->bound) {
c = task->threadid;
} else if (c < 0) {
c = atomic_fetch_add_explicit(&task->manager->curq, 1,
memory_order_relaxed);
}
c %= task->manager->workers;
UNUSED(c);
c = isc_random_uniform(task->manager->workers);
/*
* We're trying hard to hold locks for as short a time as possible.
@@ -567,13 +535,9 @@ isc_task_sendtoanddetach(isc_task_t **taskp, isc_event_t **eventp, int c) {
REQUIRE(VALID_TASK(task));
XTRACE("isc_task_sendanddetach");
if (task->bound) {
c = task->threadid;
} else if (c < 0) {
c = atomic_fetch_add_explicit(&task->manager->curq, 1,
memory_order_relaxed);
}
c %= task->manager->workers;
UNUSED(c);
c = isc_random_uniform(task->manager->workers);
LOCK(&task->lock);
idle1 = task_send(task, eventp, c);
+205 -179
View File
@@ -345,16 +345,13 @@ struct isc__socket {
int fd;
int pf;
int threadid;
char name[16];
void * tag;
char name[16];
void * tag;
bool recv_subscribed;
isc_socketevent_factory_t recv_subscriber;
void *recv_subscriber_arg;
ISC_LIST(isc_socketevent_t) send_list;
isc_socketevent_t* recv_event;
isc_socket_newconnev_t* accept_event;
isc_socket_connev_t* connect_event;
ISC_LIST(isc_socketevent_t) recv_list;
ISC_LIST(isc_socket_newconnev_t) accept_list;
ISC_LIST(isc_socket_connev_t) connect_list;
isc_sockaddr_t peer_address; /* remote address */
@@ -688,7 +685,6 @@ dec_stats(isc_stats_t *stats, isc_statscounter_t counterid) {
static inline isc_result_t
watch_fd(isc__socketthread_t *thread, int fd, int msg) {
isc_result_t result = ISC_R_SUCCESS;
//printf("WATCH %d\n", fd);
#ifdef USE_KQUEUE
struct kevent evchange;
@@ -775,7 +771,7 @@ watch_fd(isc__socketthread_t *thread, int fd, int msg) {
static inline isc_result_t
unwatch_fd(isc__socketthread_t *thread, int fd, int msg) {
isc_result_t result = ISC_R_SUCCESS;
//printf("UNWATCH %d\n", fd);
#ifdef USE_KQUEUE
struct kevent evchange;
@@ -1667,10 +1663,8 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) {
* If we read less than we expected, update counters,
* and let the upper layer poke the descriptor.
*/
if (((size_t)cc != read_count) && (dev->n < dev->minimum)) {
//printf("Incomplete read\n");
if (((size_t)cc != read_count) && (dev->n < dev->minimum))
return (DOIO_SOFT);
}
/*
* Full reads are posted, or partials if partials are ok.
@@ -1872,10 +1866,10 @@ destroy(isc__socket_t **sockp) {
socket_log(sock, NULL, CREATION, isc_msgcat, ISC_MSGSET_SOCKET,
ISC_MSG_DESTROYING, "destroying");
INSIST(sock->connect_event == NULL);
INSIST(sock->accept_event == NULL);
INSIST(sock->recv_event == NULL);
INSIST(sock->recv_event == NULL);
INSIST(ISC_LIST_EMPTY(sock->connect_list));
INSIST(ISC_LIST_EMPTY(sock->accept_list));
INSIST(ISC_LIST_EMPTY(sock->recv_list));
INSIST(ISC_LIST_EMPTY(sock->send_list));
INSIST(sock->fd >= -1 && sock->fd < (int)manager->maxsocks);
if (sock->fd >= 0) {
@@ -1926,14 +1920,12 @@ allocate_socket(isc__socketmgr_t *manager, isc_sockettype_t type,
sock->tag = NULL;
/*
* Set up readers and writers to be initially empty.
* Set up list of readers and writers to be initially empty.
*/
ISC_LIST_INIT(sock->recv_list);
ISC_LIST_INIT(sock->send_list);
sock->recv_event = NULL;
sock->accept_event = NULL;
sock->connect_event = NULL;
sock->recv_subscribed = false;
sock->recv_subscriber = NULL;
ISC_LIST_INIT(sock->accept_list);
ISC_LIST_INIT(sock->connect_list);
sock->listener = 0;
sock->connected = 0;
sock->connecting = 0;
@@ -1966,10 +1958,10 @@ free_socket(isc__socket_t **socketp) {
INSIST(VALID_SOCKET(sock));
INSIST(isc_refcount_current(&sock->references) == 0);
INSIST(!sock->connecting);
INSIST(sock->connect_event == NULL);
INSIST(sock->accept_event == NULL);
INSIST(sock->recv_event == NULL);
INSIST(sock->recv_event == NULL);
INSIST(ISC_LIST_EMPTY(sock->recv_list));
INSIST(ISC_LIST_EMPTY(sock->send_list));
INSIST(ISC_LIST_EMPTY(sock->accept_list));
INSIST(ISC_LIST_EMPTY(sock->connect_list));
INSIST(!ISC_LINK_LINKED(sock, link));
sock->common.magic = 0;
@@ -2769,10 +2761,10 @@ isc_socket_close(isc_socket_t *sock0) {
REQUIRE(sock->fd >= 0 && sock->fd < (int)sock->manager->maxsocks);
INSIST(!sock->connecting);
INSIST(sock->connect_event == NULL);
INSIST(sock->accept_event == NULL);
INSIST(sock->recv_event == NULL);
INSIST(sock->recv_event == NULL);
INSIST(ISC_LIST_EMPTY(sock->recv_list));
INSIST(ISC_LIST_EMPTY(sock->send_list));
INSIST(ISC_LIST_EMPTY(sock->accept_list));
INSIST(ISC_LIST_EMPTY(sock->connect_list));
manager = sock->manager;
thread = &manager->threads[sock->threadid];
@@ -2814,8 +2806,8 @@ send_recvdone_event(isc__socket_t *sock, isc_socketevent_t **dev) {
(*dev)->ev_sender = sock;
if (sock->recv_event == *dev) {
sock->recv_event = NULL;
if (ISC_LINK_LINKED(*dev, ev_link)) {
ISC_LIST_DEQUEUE(sock->recv_list, *dev, ev_link);
}
if (((*dev)->attributes & ISC_SOCKEVENTATTR_ATTACHED) != 0) {
@@ -2824,7 +2816,6 @@ send_recvdone_event(isc__socket_t *sock, isc_socketevent_t **dev) {
} else {
isc_task_sendto(task, (isc_event_t **)dev, sock->threadid);
}
*dev = NULL;
}
/*
@@ -2866,8 +2857,8 @@ send_connectdone_event(isc__socket_t *sock, isc_socket_connev_t **dev) {
task = (*dev)->ev_sender;
(*dev)->ev_sender = sock;
if (sock->connect_event == *dev) {
sock->connect_event = NULL;
if (ISC_LINK_LINKED(*dev, ev_link)) {
ISC_LIST_DEQUEUE(sock->connect_list, *dev, ev_link);
}
isc_task_sendtoanddetach(&task, (isc_event_t **)dev, sock->threadid);
@@ -2913,7 +2904,7 @@ internal_accept(isc__socket_t *sock) {
* Get the first item off the accept list.
* If it is empty, unlock the socket and return.
*/
dev = sock->accept_event;
dev = ISC_LIST_HEAD(sock->accept_list);
if (dev == NULL) {
unwatch_fd(thread, sock->fd, SELECT_POKE_ACCEPT);
UNLOCK(&sock->lock);
@@ -3036,13 +3027,14 @@ internal_accept(isc__socket_t *sock) {
/*
* Pull off the done event.
*/
sock->accept_event = NULL;
ISC_LIST_UNLINK(sock->accept_list, dev, ev_link);
/*
* Poke watcher if there are more pending accepts.
*/
unwatch_fd(thread, sock->fd,
SELECT_POKE_ACCEPT);
if (ISC_LIST_EMPTY(sock->accept_list))
unwatch_fd(thread, sock->fd,
SELECT_POKE_ACCEPT);
UNLOCK(&sock->lock);
@@ -3140,23 +3132,11 @@ internal_accept(isc__socket_t *sock) {
static void
internal_recv(isc__socket_t *sock) {
isc_socketevent_t *dev;
isc_result_t result;
INSIST(VALID_SOCKET(sock));
LOCK(&sock->lock);
dev = sock->recv_event;
//printf("sock %p dev %p subscribed %d\n", sock, dev, sock->recv_subscribed);
if (dev == NULL && sock->recv_subscribed) {
result = sock->recv_subscriber(sock->recv_subscriber_arg,
&sock->recv_event);
if (result == ISC_R_QUOTA) {
// Unsubscribe
//printf("Unsubscribing %p because of %s\n", sock, isc_result_totext(result));
sock->recv_subscribed = false;
} /* XXXWPK TODO log outher failures? */
//printf("new %p\n", sock->recv_event);
}
dev = sock->recv_event;
dev = ISC_LIST_HEAD(sock->recv_list);
if (dev == NULL) {
goto finish;
}
@@ -3164,36 +3144,40 @@ internal_recv(isc__socket_t *sock) {
socket_log(sock, NULL, IOEVENT,
isc_msgcat, ISC_MSGSET_SOCKET, ISC_MSG_INTERNALRECV,
"internal_recv: event %p -> task %p", dev, dev->ev_sender);
/*
* Try to do as much I/O as possible on this socket. There are no
* limits here, currently.
*/
while (dev != NULL) {
//printf("Receiving...\n");
result = doio_recv(sock, dev);
if (result == DOIO_EOF) {
dev->result = ISC_R_EOF;
}
if (result != DOIO_SOFT) {
//printf("recv succ %p %s\n", sock, isc_result_totext(dev->result));
send_recvdone_event(sock, &dev);
} else {
//printf("Soft err\n");
switch (doio_recv(sock, dev)) {
case DOIO_SOFT:
goto finish;
case DOIO_EOF:
/*
* read of 0 means the remote end was closed.
* Run through the event queue and dispatch all
* the events with an EOF result code.
*/
do {
dev->result = ISC_R_EOF;
send_recvdone_event(sock, &dev);
dev = ISC_LIST_HEAD(sock->recv_list);
} while (dev != NULL);
goto finish;
case DOIO_SUCCESS:
case DOIO_HARD:
send_recvdone_event(sock, &dev);
break;
}
if (dev == NULL && sock->recv_subscribed) {
//printf("RETRY RETRY\n");
result = sock->recv_subscriber(sock->recv_subscriber_arg,
&sock->recv_event);
if (result == ISC_R_QUOTA) {
// Unsubscribe
//printf("Unsubscribing %p because of %s\n", sock, isc_result_totext(result));
sock->recv_subscribed = false;
} /* XXXWPK TODO log outher failures? */
//printf("new %p %d\n", sock->recv_event, result);
}
dev = sock->recv_event;
dev = ISC_LIST_HEAD(sock->recv_list);
}
finish:
if (sock->recv_event == NULL && !sock->recv_subscribed) {
//printf("Unwatching\n");
if (ISC_LIST_EMPTY(sock->recv_list)) {
unwatch_fd(&sock->manager->threads[sock->threadid], sock->fd,
SELECT_POKE_READ);
}
@@ -3211,7 +3195,6 @@ internal_send(isc__socket_t *sock) {
if (dev == NULL) {
goto finish;
}
//printf("internal send %p\n", sock);
socket_log(sock, NULL, EVENT, NULL, 0, 0,
"internal_send: event %p -> task %p",
dev, dev->ev_sender);
@@ -3220,7 +3203,6 @@ internal_send(isc__socket_t *sock) {
* Try to do as much I/O as possible on this socket. There are no
* limits here, currently.
*/
while (dev != NULL) {
switch (doio_send(sock, dev)) {
case DOIO_SOFT:
@@ -3251,7 +3233,6 @@ static void
process_fd(isc__socketthread_t *thread, int fd, bool readable,
bool writeable)
{
//printf("Process fd %d\n", fd);
isc__socket_t *sock;
int lockid = FDLOCK_ID(fd);
@@ -4076,6 +4057,84 @@ 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,
unsigned int flags)
{
int io_state;
bool have_lock = false;
isc_task_t *ntask = NULL;
isc_result_t result = ISC_R_SUCCESS;
dev->ev_sender = task;
if (sock->type == isc_sockettype_udp) {
io_state = doio_recv(sock, dev);
} else {
LOCK(&sock->lock);
have_lock = true;
if (ISC_LIST_EMPTY(sock->recv_list)) {
io_state = doio_recv(sock, dev);
} else {
io_state = DOIO_SOFT;
}
}
switch (io_state) {
case DOIO_SOFT:
/*
* We couldn't read all or part of the request right now, so
* queue it.
*
* Attach to socket and to task
*/
isc_task_attach(task, &ntask);
dev->attributes |= ISC_SOCKEVENTATTR_ATTACHED;
if (!have_lock) {
LOCK(&sock->lock);
have_lock = true;
}
/*
* Enqueue the request. If the socket was previously not being
* watched, poke the watcher to start paying attention to it.
*/
bool do_poke = ISC_LIST_EMPTY(sock->recv_list);
ISC_LIST_ENQUEUE(sock->recv_list, dev, ev_link);
if (do_poke) {
select_poke(sock->manager, sock->threadid, sock->fd,
SELECT_POKE_READ);
}
socket_log(sock, NULL, EVENT, NULL, 0, 0,
"socket_recv: event %p -> task %p",
dev, ntask);
if ((flags & ISC_SOCKFLAG_IMMEDIATE) != 0) {
result = ISC_R_INPROGRESS;
}
break;
case DOIO_EOF:
dev->result = ISC_R_EOF;
/* fallthrough */
case DOIO_HARD:
case DOIO_SUCCESS:
if ((flags & ISC_SOCKFLAG_IMMEDIATE) == 0) {
send_recvdone_event(sock, &dev);
}
break;
}
if (have_lock) {
UNLOCK(&sock->lock);
}
return (result);
}
isc_result_t
isc_socket_recv(isc_socket_t *sock0, isc_region_t *region,
@@ -4128,31 +4187,7 @@ isc_socket_recv2(isc_socket_t *sock0, isc_region_t *region,
event->minimum = minimum;
}
isc_task_t *ntask = NULL;
isc_result_t result = ISC_R_SUCCESS;
event->ev_sender = task;
LOCK(&sock->lock);
INSIST(sock->recv_event == NULL);
sock->recv_event = event;
UNLOCK(&sock->lock);
isc_task_attach(task, &ntask);
event->attributes |= ISC_SOCKEVENTATTR_ATTACHED;
select_poke(sock->manager, sock->threadid, sock->fd,
SELECT_POKE_READ);
socket_log(sock, NULL, EVENT, NULL, 0, 0,
"socket_recv: event %p -> task %p",
event, ntask);
if ((flags & ISC_SOCKFLAG_IMMEDIATE) != 0) {
result = ISC_R_INPROGRESS;
}
return (result);
return (socket_recv(sock, event, task, flags));
}
static isc_result_t
@@ -4192,6 +4227,7 @@ socket_send(isc__socket_t *sock, isc_socketevent_t *dev, isc_task_t *task,
} else {
LOCK(&sock->lock);
have_lock = true;
if (ISC_LIST_EMPTY(sock->send_list)) {
io_state = doio_send(sock, dev);
} else {
@@ -4240,7 +4276,6 @@ socket_send(isc__socket_t *sock, isc_socketevent_t *dev, isc_task_t *task,
case DOIO_HARD:
case DOIO_SUCCESS:
//printf("send immediate %p\n", sock);
if ((flags & ISC_SOCKFLAG_IMMEDIATE) == 0) {
send_senddone_event(sock, &dev);
}
@@ -4741,13 +4776,13 @@ isc_socket_accept(isc_socket_t *sock0,
isc_task_t *ntask = NULL;
isc__socket_t *nsock;
isc_result_t result;
bool do_poke = false;
REQUIRE(VALID_SOCKET(sock));
manager = sock->manager;
REQUIRE(VALID_MANAGER(manager));
LOCK(&sock->lock);
INSIST(sock->connect_event == NULL);
REQUIRE(sock->listener);
@@ -4794,9 +4829,12 @@ isc_socket_accept(isc_socket_t *sock0,
* is no race condition. We will keep the lock for such a short
* bit of time waking it up now or later won't matter all that much.
*/
sock->accept_event = dev;
select_poke(manager, sock->threadid, sock->fd,
SELECT_POKE_ACCEPT);
do_poke = ISC_LIST_EMPTY(sock->accept_list);
ISC_LIST_ENQUEUE(sock->accept_list, dev, ev_link);
if (do_poke) {
select_poke(manager, sock->threadid, sock->fd,
SELECT_POKE_ACCEPT);
}
UNLOCK(&sock->lock);
return (ISC_R_SUCCESS);
}
@@ -4826,7 +4864,6 @@ isc_socket_connect(isc_socket_t *sock0, const isc_sockaddr_t *addr,
return (ISC_R_MULTICAST);
LOCK(&sock->lock);
INSIST(sock->connect_event == NULL);
dev = (isc_socket_connev_t *)isc_event_allocate(manager->mctx, sock,
ISC_SOCKEVENT_CONNECT,
@@ -4950,8 +4987,9 @@ isc_socket_connect(isc_socket_t *sock0, const isc_sockaddr_t *addr,
* is no race condition. We will keep the lock for such a short
* bit of time waking it up now or later won't matter all that much.
*/
sock->connect_event = dev;
if (!sock->connecting) {
bool do_poke = ISC_LIST_EMPTY(sock->connect_list);
ISC_LIST_ENQUEUE(sock->connect_list, dev, ev_link);
if (do_poke && !sock->connecting) {
sock->connecting = 1;
select_poke(manager, sock->threadid, sock->fd,
SELECT_POKE_CONNECT);
@@ -4981,7 +5019,7 @@ internal_connect(isc__socket_t *sock) {
* Get the first item off the connect list.
* If it is empty, unlock the socket and return.
*/
dev = sock->connect_event;
dev = ISC_LIST_HEAD(sock->connect_list);
if (dev == NULL) {
INSIST(!sock->connecting);
goto finish;
@@ -5051,8 +5089,11 @@ internal_connect(isc__socket_t *sock) {
sock->bound = 1;
}
dev->result = result;
send_connectdone_event(sock, &dev);
do {
dev->result = result;
send_connectdone_event(sock, &dev);
dev = ISC_LIST_HEAD(sock->connect_list);
} while (dev != NULL);
finish:
unwatch_fd(&sock->manager->threads[sock->threadid], sock->fd,
@@ -5148,16 +5189,22 @@ isc_socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) {
* o Reset any state needed.
*/
if (((how & ISC_SOCKCANCEL_RECV) != 0)
&& sock->recv_event != NULL) {
&& !ISC_LIST_EMPTY(sock->recv_list)) {
isc_socketevent_t *dev;
isc_socketevent_t *next;
isc_task_t *current_task;
dev = sock->recv_event;
dev = ISC_LIST_HEAD(sock->recv_list);
current_task = dev->ev_sender;
if ((task == NULL) || (task == current_task)) {
dev->result = ISC_R_CANCELED;
send_recvdone_event(sock, &dev);
while (dev != NULL) {
current_task = dev->ev_sender;
next = ISC_LIST_NEXT(dev, ev_link);
if ((task == NULL) || (task == current_task)) {
dev->result = ISC_R_CANCELED;
send_recvdone_event(sock, &dev);
}
dev = next;
}
}
@@ -5172,6 +5219,7 @@ isc_socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) {
while (dev != NULL) {
current_task = dev->ev_sender;
next = ISC_LIST_NEXT(dev, ev_link);
if ((task == NULL) || (task == current_task)) {
dev->result = ISC_R_CANCELED;
send_senddone_event(sock, &dev);
@@ -5181,41 +5229,54 @@ isc_socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) {
}
if (((how & ISC_SOCKCANCEL_ACCEPT) != 0)
&& sock->accept_event != NULL) {
&& !ISC_LIST_EMPTY(sock->accept_list)) {
isc_socket_newconnev_t *dev;
isc_socket_newconnev_t *next;
isc_task_t *current_task;
dev = sock->accept_event;
current_task = dev->ev_sender;
dev = ISC_LIST_HEAD(sock->accept_list);
while (dev != NULL) {
current_task = dev->ev_sender;
next = ISC_LIST_NEXT(dev, ev_link);
if ((task == NULL) || (task == current_task)) {
sock->accept_event = NULL;
if ((task == NULL) || (task == current_task)) {
NEWCONNSOCK(dev)->references--;
free_socket((isc__socket_t **)&dev->newsocket);
ISC_LIST_UNLINK(sock->accept_list, dev,
ev_link);
dev->result = ISC_R_CANCELED;
dev->ev_sender = sock;
isc_task_sendtoanddetach(&current_task,
ISC_EVENT_PTR(&dev), sock->threadid);
NEWCONNSOCK(dev)->references--;
free_socket((isc__socket_t **)&dev->newsocket);
dev->result = ISC_R_CANCELED;
dev->ev_sender = sock;
isc_task_sendtoanddetach(&current_task,
ISC_EVENT_PTR(&dev), sock->threadid);
}
dev = next;
}
}
if (((how & ISC_SOCKCANCEL_CONNECT) != 0)
&& sock->connect_event != NULL) {
&& !ISC_LIST_EMPTY(sock->connect_list)) {
isc_socket_connev_t *dev;
isc_socket_connev_t *next;
isc_task_t *current_task;
INSIST(sock->connecting);
sock->connecting = 0;
dev = sock->connect_event;
dev = ISC_LIST_HEAD(sock->connect_list);
current_task = dev->ev_sender;
while (dev != NULL) {
current_task = dev->ev_sender;
next = ISC_LIST_NEXT(dev, ev_link);
if ((task == NULL) || (task == current_task)) {
dev->result = ISC_R_CANCELED;
send_connectdone_event(sock, &dev);
if ((task == NULL) || (task == current_task)) {
dev->result = ISC_R_CANCELED;
send_connectdone_event(sock, &dev);
}
dev = next;
}
}
@@ -5392,13 +5453,10 @@ init_hasreuseport() {
int sock, yes = 1;
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
sock = socket(AF_INET6, SOCK_DGRAM, 0);
if (sock < 0) {
return;
}
}
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(void *)&yes, sizeof(yes)) < 0)
close(sock);
return;
} else if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(void *)&yes, sizeof(yes)) < 0)
{
close(sock);
return;
@@ -5409,7 +5467,6 @@ init_hasreuseport() {
return;
}
hasreuseport = true;
close(sock);
#endif
}
@@ -5661,34 +5718,3 @@ isc_socketmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
return (result);
}
isc_result_t
isc_socket_udpsubscribe(isc_socket_t *usock, isc_socketevent_factory_t evf, void* arg) {
isc__socket_t *sock = (isc__socket_t*) usock;
REQUIRE(sock->recv_subscriber == NULL);
REQUIRE(sock->recv_event == NULL);
LOCK(&sock->lock);
sock->recv_subscriber = evf;
sock->recv_subscriber_arg = arg;
sock->recv_subscribed = true;
UNLOCK(&sock->lock);
select_poke(sock->manager, sock->threadid, sock->fd,
SELECT_POKE_READ);
return (ISC_R_SUCCESS);
}
void
isc_socket_udpsubscription_toggle(isc_socket_t *usock, bool on) {
isc__socket_t *sock = (isc__socket_t*) usock;
bool old;
LOCK(&sock->lock);
REQUIRE(sock->recv_subscriber != NULL);
old = sock->recv_subscribed;
sock->recv_subscribed = on;
UNLOCK(&sock->lock);
if (!old && on) {
//printf("Re-subscribing %p\n", sock);
select_poke(sock->manager, sock->threadid, sock->fd,
SELECT_POKE_READ);
}
}
+2 -1
View File
@@ -364,6 +364,7 @@ isc_mem_createx
isc_mem_destroy
isc_mem_detach
isc_mem_getname
isc_mem_getquota
isc_mem_gettag
isc_mem_inuse
isc_mem_isovermem
@@ -377,6 +378,7 @@ isc_mem_renderxml
@END LIBXML2
isc_mem_setdestroycheck
isc_mem_setname
isc_mem_setquota
isc_mem_setwater
isc_mem_stats
isc_mem_total
@@ -566,7 +568,6 @@ isc_syslog_facilityfromstring
isc_task_attach
isc_task_beginexclusive
isc_task_create
isc_task_create_bound
isc_task_destroy
isc_task_detach
isc_task_endexclusive
+2 -184
View File
@@ -156,13 +156,6 @@ struct ns_clientmgr {
#define MANAGER_MAGIC ISC_MAGIC('N', 'S', 'C', 'm')
#define VALID_MANAGER(m) ISC_MAGIC_VALID(m, MANAGER_MAGIC)
typedef struct create_udp_socketevent_arg {
ns_clientmgr_t *manager;
isc_socket_t *socket;
ns_interface_t *interface;
int disp;
} create_udp_socketevent_arg_t;
/*!
* Client object states. Ordering is significant: higher-numbered
* states are generally "more active", meaning that the client can
@@ -254,8 +247,6 @@ static isc_result_t get_worker(ns_clientmgr_t *manager, ns_interface_t *ifp,
static void compute_cookie(ns_client_t *client, uint32_t when,
uint32_t nonce, const unsigned char *secret,
isc_buffer_t *buf);
static isc_result_t
ns__create_udp_socketevent(void* argp, isc_socketevent_t **sockevp);
void
ns_client_recursing(ns_client_t *client) {
@@ -533,14 +524,6 @@ exit_check(ns_client_t *client) {
if (client->nctls > 0)
return (true);
/* We need to do it before detaching interface */
if (client->udpinflightquota != NULL) {
if (isc_quota_detach_verbose(&client->udpinflightquota) == ISC_R_SUCCESS) {
/* We are back 'in quota', can reenable subscribtion to socket */
isc_socket_udpsubscription_toggle(client->udpsocket, true);
}
}
/* Deactivate the client. */
if (client->interface)
ns_interface_detach(&client->interface);
@@ -549,8 +532,7 @@ exit_check(ns_client_t *client) {
INSIST(client->recursionquota == NULL);
if (client->tcplistener != NULL)
isc_socket_detach(&client->tcplistener);
if (client->udpsocket != NULL)
isc_socket_detach(&client->udpsocket);
@@ -790,7 +772,7 @@ ns_client_endrequest(ns_client_t *client) {
ns_stats_decrement(client->sctx->nsstats,
ns_statscounter_recursclients);
}
/*
* Clear all client attributes that are specific to
* the request; that's all except the TCP flag.
@@ -1067,51 +1049,6 @@ ns_client_sendraw(ns_client_t *client, dns_message_t *message) {
ns_client_next(client, result);
}
#ifdef PSEUDOSEND
static void
client_pseudosend(ns_client_t *client, uint16_t id) {
isc_result_t result;
unsigned char *data;
isc_buffer_t buffer;
isc_buffer_t tcpbuffer;
isc_region_t r;
unsigned char sendbuf[SEND_BUFFER_SIZE];
result = client_allocsendbuf(client, &buffer, &tcpbuffer, 0,
sendbuf, &data);
if (result != ISC_R_SUCCESS) {
goto done;
}
isc_buffer_putuint16(&buffer, id);
isc_buffer_putuint8(&buffer, 0x81);
isc_buffer_putuint8(&buffer, 0x80);
isc_buffer_putuint16(&buffer, 0);
isc_buffer_putuint16(&buffer, 0);
isc_buffer_putuint16(&buffer, 0);
isc_buffer_putuint16(&buffer, 0);
if (client->sendcb != NULL) {
client->sendcb(&buffer);
} else if (TCP_CLIENT(client)) {
isc_buffer_usedregion(&buffer, &r);
isc_buffer_putuint16(&tcpbuffer, (uint16_t) r.length);
isc_buffer_add(&tcpbuffer, r.length);
result = client_sendpkg(client, &tcpbuffer);
} else {
result = client_sendpkg(client, &buffer);
}
if (result == ISC_R_SUCCESS) {
return;
}
done:
if (client->tcpbuf != NULL) {
isc_mem_put(client->mctx, client->tcpbuf, TCP_BUFFER_SIZE);
client->tcpbuf = NULL;
}
ns_client_next(client, result);
}
#endif
static void
client_send(ns_client_t *client) {
isc_result_t result;
@@ -2398,20 +2335,6 @@ ns__client_request(isc_task_t *task, isc_event_t *event) {
return;
}
#ifdef PSEUDOSEND
result = dns_message_peekheader(buffer, &id, &flags);
if (result != ISC_R_SUCCESS) {
/*
* There isn't enough header to determine whether
* this was a request or a response. Drop it.
*/
ns_client_next(client, result);
return;
}
client_pseudosend(client, id);
return;
#endif
isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr);
#if NS_CLIENT_DROPPORT
@@ -3122,7 +3045,6 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp) {
client->recursionquota = NULL;
client->interface = NULL;
client->peeraddr_valid = false;
client->udpinflightquota = NULL;
dns_ecs_init(&client->ecs);
client->filter_aaaa = dns_aaaa_ok;
client->needshutdown = (client->sctx->options & NS_SERVER_CLIENTTEST);
@@ -3788,26 +3710,6 @@ ns_clientmgr_createclients(ns_clientmgr_t *manager, unsigned int n,
return (result);
}
isc_result_t
ns_clientmgr_subscribe_clients(ns_clientmgr_t *manager, unsigned int n, ns_interface_t *ifp) {
isc_result_t result = ISC_R_SUCCESS;
unsigned int disp;
create_udp_socketevent_arg_t *arg;
for (disp = 0; disp < n; disp++) {
arg = malloc(sizeof(*arg));
arg->manager = manager;
arg->socket = dns_dispatch_getsocket(ifp->udpdispatch[disp]);
arg->interface = ifp;
arg->disp = disp;
result = isc_socket_udpsubscribe(arg->socket, &ns__create_udp_socketevent, arg);
if (result != ISC_R_SUCCESS) {
break;
}
}
return (result);
}
isc_sockaddr_t *
ns_client_getsockaddr(ns_client_t *client) {
return (&client->peeraddr);
@@ -4095,87 +3997,3 @@ ns_client_sourceip(dns_clientinfo_t *ci, isc_sockaddr_t **addrp) {
*addrp = &client->peeraddr;
return (ISC_R_SUCCESS);
}
static isc_result_t
ns__create_udp_socketevent(void* argp, isc_socketevent_t **sockevp) {
create_udp_socketevent_arg_t *arg = (create_udp_socketevent_arg_t*)argp;
ns_clientmgr_t *manager = arg->manager;
isc_socket_t *sock = arg->socket;
isc_socketevent_t *sev;
ns_client_t *client;
isc_result_t result;
isc_quota_t* inflightquota = NULL;
MTRACE("create_udp_socketevent");
REQUIRE(manager != NULL);
if (manager->exiting) {
return (ISC_R_FAILURE);
}
result = isc_quota_attach(&arg->interface->udpinflightquota[arg->disp], &inflightquota);
if (result == ISC_R_QUOTA) {
return (ISC_R_QUOTA);
}
/*
* Allocate a client. First try to get a recycled one;
* if that fails, make a new one.
*/
client = NULL;
if ((manager->sctx->options & NS_SERVER_CLIENTTEST) == 0)
ISC_QUEUE_POP(manager->inactive, ilink, client);
if (client != NULL) {
MTRACE("recycle");
} else {
MTRACE("create new");
LOCK(&manager->lock);
result = client_create(manager, &client);
UNLOCK(&manager->lock);
if (result != ISC_R_SUCCESS) {
printf("Cant create client %s\n", isc_result_totext(result));
return (result);
}
LOCK(&manager->listlock);
ISC_LIST_APPEND(manager->clients, client, link);
UNLOCK(&manager->listlock);
}
ns_interface_attach(arg->interface, &client->interface);
client->manager = manager;
client->mortal = true;
client->state = NS_CLIENTSTATE_READY;
client->sctx = manager->sctx;
INSIST(client->udpinflightquota == NULL);
INSIST(client->recursionquota == NULL);
client->dscp = arg->interface->dscp;
client->mortal = true;
client->udpinflightquota = inflightquota;
isc_socket_attach(sock, &client->udpsocket);
INSIST(client->nctls == 0);
if (exit_check(client)) {
printf("exit _check\n");
return (ISC_R_FAILURE);
}
sev = client->recvevent;
sev->ev_sender = client->task;
sev->ev_arg = client;
sev->result = ISC_R_UNSET;
sev->n = 0;
sev->offset = 0;
sev->attributes = 0;
sev->region.base = client->recvbuf;
sev->region.length = RECV_BUFFER_SIZE;
sev->minimum = 1;
client->nrecvs++;
*sockevp = sev;
return (result);
}
-4
View File
@@ -136,7 +136,6 @@ struct ns_client {
bool pipelined; /*%< TCP queries not in sequence */
isc_quota_t *tcpquota;
isc_quota_t *recursionquota;
isc_quota_t *udpinflightquota;
ns_interface_t *interface;
isc_sockaddr_t peeraddr;
@@ -422,9 +421,6 @@ ns__clientmgr_getclient(ns_clientmgr_t *manager, ns_interface_t *ifp,
* (Not intended for use outside this module and associated tests.)
*/
isc_result_t
ns_clientmgr_subscribe_clients(ns_clientmgr_t*, unsigned int, ns_interface_t*);
void
ns__client_request(isc_task_t *task, isc_event_t *event);
/*
-2
View File
@@ -44,7 +44,6 @@
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/quota.h>
#include <isc/socket.h>
#include <dns/geoip.h>
@@ -83,7 +82,6 @@ struct ns_interface {
int nudpdispatch; /*%< Number of UDP dispatches */
ns_clientmgr_t * clientmgr; /*%< Client manager. */
ISC_LINK(ns_interface_t) link;
isc_quota_t udpinflightquota[100]; /*%< Number of UDP clients in flight. */
};
/***
+2 -10
View File
@@ -220,7 +220,6 @@ ns_interfacemgr_create(isc_mem_t *mctx,
ISC_LIST_INIT(mgr->interfaces);
ISC_LIST_INIT(mgr->listenon);
/*
* The listen-on lists are initially empty.
@@ -430,12 +429,6 @@ ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr,
ifp->ntcpcurrent = 0;
ifp->nudpdispatch = 0;
/* XXXWPK TODO */
for (int i=0; i<100; i++) {
isc_quota_init(&ifp->udpinflightquota[i], 150);
isc_quota_soft(&ifp->udpinflightquota[i], 120);
}
ifp->dscp = -1;
ISC_LINK_INIT(ifp, link);
@@ -498,9 +491,8 @@ ns_interface_listenudp(ns_interface_t *ifp) {
}
result = ns_clientmgr_subscribe_clients(ifp->clientmgr,
ifp->nudpdispatch,
ifp);
result = ns_clientmgr_createclients(ifp->clientmgr, ifp->nudpdispatch,
ifp, false);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"UDP ns_clientmgr_createclients(): %s",
-15
View File
@@ -1,15 +0,0 @@
#!/bin/sh
ret=0
for spatch in cocci/*.spatch; do
patch="$(dirname "$spatch")/$(basename "$spatch" .spatch).patch"
spatch --sp-file="$spatch" --use-gitgrep --dir . --very-quiet > "$patch";
if [ "$(< "$patch" wc -l)" -gt "0" ]; then
cat "$patch"
ret=1
else
rm "$patch"
fi
done
exit $ret
-2
View File
@@ -1285,7 +1285,6 @@
./bin/win32/BINDInstall/resource.h X 2001,2005,2009,2018
./bind.keys X 2009,2010,2011,2017,2018
./bind.keys.h X 2009,2010,2011,2012,2014,2017,2018
./cocci/unreachable.spatch X 2018
./config.guess X 1998,1999,2000,2001,2004,2009,2013,2018
./config.h.in X 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018
./config.h.win32 C 1999,2000,2001,2004,2006,2007,2008,2009,2011,2012,2013,2014,2015,2016,2017,2018
@@ -2569,7 +2568,6 @@
./util/branchsync.sh SH 2013,2016,2018
./util/check-categories.sh SH 2015,2016,2017,2018
./util/check-changes PERL 2002,2004,2007,2012,2016,2018
./util/check-cocci X 2018
./util/check-includes.pl PERL 2000,2001,2004,2007,2012,2016,2017,2018
./util/check-instincludes.sh SH 2000,2001,2004,2007,2012,2016,2018
./util/check-pullups.pl PERL 2001,2002,2003,2004,2007,2012,2016,2018