Merge branch 'ondrej-refactor-isc_buffer-for-dnsstream' into 'main'

Change the isc_buffer_reserve() to take just buffer pointer

See merge request isc-projects/bind9!7235
This commit is contained in:
Ondřej Surý 2022-12-20 19:22:12 +00:00
commit 858e06e58d
19 changed files with 718 additions and 764 deletions

View file

@ -7971,8 +7971,8 @@ data_to_cfg(dns_view_t *view, MDB_val *key, MDB_val *data, isc_buffer_t **text,
INSIST(zone_config != NULL && zone_config_len > 0);
/* zone zonename { config; }; */
result = isc_buffer_reserve(text, 6 + zone_name_len + 2 +
zone_config_len + 2);
result = isc_buffer_reserve(*text, 6 + zone_name_len + 2 +
zone_config_len + 2);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
@ -12474,7 +12474,7 @@ named_server_testgen(isc_lex_t *lex, isc_buffer_t **text) {
count = strtoul(ptr, NULL, 10);
}
CHECK(isc_buffer_reserve(text, count));
CHECK(isc_buffer_reserve(*text, count));
for (i = 0; i < count; i++) {
CHECK(putuint8(text, chars[i % (sizeof(chars) - 1)]));
}
@ -15422,7 +15422,7 @@ static isc_result_t
putmem(isc_buffer_t **b, const char *str, size_t len) {
isc_result_t result;
result = isc_buffer_reserve(b, (unsigned int)len);
result = isc_buffer_reserve(*b, (unsigned int)len);
if (result != ISC_R_SUCCESS) {
return (ISC_R_NOSPACE);
}
@ -15440,7 +15440,7 @@ static isc_result_t
putuint8(isc_buffer_t **b, uint8_t val) {
isc_result_t result;
result = isc_buffer_reserve(b, 1);
result = isc_buffer_reserve(*b, 1);
if (result != ISC_R_SUCCESS) {
return (ISC_R_NOSPACE);
}

View file

@ -186,7 +186,7 @@ main(int argc, char *argv[]) {
if (rawdata) {
while (fread(&c, 1, 1, f) != 0) {
result = isc_buffer_reserve(&input, 1);
result = isc_buffer_reserve(input, 1);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
isc_buffer_putuint8(input, (uint8_t)c);
}
@ -223,7 +223,7 @@ main(int argc, char *argv[]) {
c = fromhex(*rp++);
c *= 16;
c += fromhex(*rp++);
result = isc_buffer_reserve(&input, 1);
result = isc_buffer_reserve(input, 1);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
isc_buffer_putuint8(input, (uint8_t)c);
}

View file

@ -157,7 +157,7 @@ print_packet(dns_dtdata_t *dt, const dns_master_style_t *style) {
}
for (;;) {
isc_buffer_reserve(&b, textlen);
isc_buffer_reserve(b, textlen);
if (b == NULL) {
fatal("out of memory");
}

View file

@ -2713,7 +2713,7 @@ static isc_result_t
putstr(isc_buffer_t **b, const char *str) {
isc_result_t result;
result = isc_buffer_reserve(b, strlen(str));
result = isc_buffer_reserve(*b, strlen(str));
if (result != ISC_R_SUCCESS) {
return (result);
}

View file

@ -1548,7 +1548,6 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp,
return (result);
}
isc_buffer_allocate(zone->catzs->mctx, &aclb, 16);
isc_buffer_setautorealloc(aclb, true);
for (result = dns_rdata_apl_first(&rdata_apl); result == ISC_R_SUCCESS;
result = dns_rdata_apl_next(&rdata_apl))
{
@ -1568,14 +1567,14 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp,
if (apl_ent.negative) {
isc_buffer_putuint8(aclb, '!');
}
isc_buffer_reserve(&aclb, INET6_ADDRSTRLEN);
isc_buffer_reserve(aclb, INET6_ADDRSTRLEN);
result = isc_netaddr_totext(&addr, aclb);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
if ((apl_ent.family == 1 && apl_ent.prefix < 32) ||
(apl_ent.family == 2 && apl_ent.prefix < 128))
{
isc_buffer_putuint8(aclb, '/');
isc_buffer_putdecint(aclb, apl_ent.prefix);
isc_buffer_printf(aclb, "%" PRId8, apl_ent.prefix);
}
isc_buffer_putstr(aclb, "; ");
}
@ -1872,7 +1871,7 @@ dns_catz_generate_masterfilename(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
rlen += strlen(entry->opts.zonedir) + 1;
}
result = isc_buffer_reserve(buffer, (unsigned int)rlen);
result = isc_buffer_reserve(*buffer, (unsigned int)rlen);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
@ -1940,7 +1939,6 @@ dns_catz_generate_zonecfg(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
*/
isc_buffer_allocate(zone->catzs->mctx, &buffer, ISC_BUFFER_INCR);
isc_buffer_setautorealloc(buffer, true);
isc_buffer_putstr(buffer, "zone \"");
dns_name_totext(&entry->name, true, buffer);
isc_buffer_putstr(buffer, "\" { type secondary; primaries");
@ -1981,7 +1979,7 @@ dns_catz_generate_zonecfg(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
}
isc_netaddr_fromsockaddr(&netaddr,
&entry->opts.masters.addrs[i]);
isc_buffer_reserve(&buffer, INET6_ADDRSTRLEN);
isc_buffer_reserve(buffer, INET6_ADDRSTRLEN);
result = isc_netaddr_totext(&netaddr, buffer);
RUNTIME_CHECK(result == ISC_R_SUCCESS);

View file

@ -884,7 +884,7 @@ static isc_result_t
putstr(isc_buffer_t **b, const char *str) {
isc_result_t result;
result = isc_buffer_reserve(b, strlen(str));
result = isc_buffer_reserve(*b, strlen(str));
if (result != ISC_R_SUCCESS) {
return (ISC_R_NOSPACE);
}
@ -1357,7 +1357,7 @@ dns_dt_datatotext(dns_dtdata_t *d, isc_buffer_t **dest) {
CHECK(putstr(dest, d->typebuf));
}
CHECK(isc_buffer_reserve(dest, 1));
CHECK(isc_buffer_reserve(*dest, 1));
isc_buffer_putuint8(*dest, 0);
cleanup:

View file

@ -618,7 +618,7 @@ static isc_result_t
putstr(isc_buffer_t **b, const char *str) {
isc_result_t result;
result = isc_buffer_reserve(b, strlen(str));
result = isc_buffer_reserve(*b, strlen(str));
if (result != ISC_R_SUCCESS) {
return (result);
}

View file

@ -478,7 +478,7 @@ static isc_result_t
putstr(isc_buffer_t **b, const char *str) {
isc_result_t result;
result = isc_buffer_reserve(b, strlen(str));
result = isc_buffer_reserve(*b, strlen(str));
if (result != ISC_R_SUCCESS) {
return (result);
}

View file

@ -11415,7 +11415,7 @@ dns_resolver_dumpquota(dns_resolver_t *res, isc_buffer_t **buf) {
" spilled %" PRIuFAST32 ")",
nb, count, allowed, dropped);
result = isc_buffer_reserve(buf, strlen(text));
result = isc_buffer_reserve(*buf, strlen(text));
if (result != ISC_R_SUCCESS) {
goto cleanup;
}

View file

@ -127,7 +127,6 @@ libisc_la_SOURCES = \
base32.c \
base64.c \
bind9.c \
buffer.c \
commandline.c \
condition.c \
counter.c \

View file

@ -1,352 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <isc/buffer.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/region.h>
#include <isc/string.h>
#include <isc/util.h>
void
isc_buffer_reinit(isc_buffer_t *b, void *base, unsigned int length) {
/*
* Re-initialize the buffer enough to reconfigure the base of the
* buffer. We will swap in the new buffer, after copying any
* data we contain into the new buffer and adjusting all of our
* internal pointers.
*
* The buffer must not be smaller than the length of the original
* buffer.
*/
REQUIRE(b->length <= length);
REQUIRE(base != NULL);
REQUIRE(!b->autore);
if (b->length > 0U) {
(void)memmove(base, b->base, b->length);
}
b->base = base;
b->length = length;
}
void
isc_buffer_setautorealloc(isc_buffer_t *b, bool enable) {
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(b->mctx != NULL);
b->autore = enable;
}
void
isc_buffer_compact(isc_buffer_t *b) {
unsigned int length;
void *src;
/*
* Compact the used region by moving the remaining region so it occurs
* at the start of the buffer. The used region is shrunk by the size
* 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);
if (length > 0U) {
(void)memmove(b->base, src, (size_t)length);
}
if (b->active > b->current) {
b->active -= b->current;
} else {
b->active = 0;
}
b->current = 0;
b->used = length;
}
uint8_t
isc_buffer_getuint8(isc_buffer_t *b) {
unsigned char *cp;
uint8_t result;
/*
* 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);
b->current += 1;
result = ((uint8_t)(cp[0]));
return (result);
}
uint16_t
isc_buffer_getuint16(isc_buffer_t *b) {
unsigned char *cp;
uint16_t result;
/*
* Read an unsigned 16-bit integer in network byte order from '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);
b->current += 2;
result = ((unsigned int)(cp[0])) << 8;
result |= ((unsigned int)(cp[1]));
return (result);
}
uint32_t
isc_buffer_getuint32(isc_buffer_t *b) {
unsigned char *cp;
uint32_t result;
/*
* Read an unsigned 32-bit integer in network byte order from '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);
b->current += 4;
result = ((unsigned int)(cp[0])) << 24;
result |= ((unsigned int)(cp[1])) << 16;
result |= ((unsigned int)(cp[2])) << 8;
result |= ((unsigned int)(cp[3]));
return (result);
}
uint64_t
isc_buffer_getuint48(isc_buffer_t *b) {
unsigned char *cp;
uint64_t result;
/*
* Read an unsigned 48-bit integer in network byte order from 'b',
* convert it to host byte order, and return it.
*/
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(b->used - b->current >= 6);
cp = isc_buffer_current(b);
b->current += 6;
result = ((int64_t)(cp[0])) << 40;
result |= ((int64_t)(cp[1])) << 32;
result |= ((int64_t)(cp[2])) << 24;
result |= ((int64_t)(cp[3])) << 16;
result |= ((int64_t)(cp[4])) << 8;
result |= ((int64_t)(cp[5]));
return (result);
}
void
isc_buffer_putdecint(isc_buffer_t *b, int64_t v) {
unsigned int l = 0;
unsigned char *cp;
char buf[21];
isc_result_t result;
REQUIRE(ISC_BUFFER_VALID(b));
/* xxxwpk do it more low-level way ? */
l = snprintf(buf, 21, "%" PRId64, v);
RUNTIME_CHECK(l <= 21);
if (b->autore) {
result = isc_buffer_reserve(&b, l);
REQUIRE(result == ISC_R_SUCCESS);
}
REQUIRE(isc_buffer_availablelength(b) >= l);
cp = isc_buffer_used(b);
memmove(cp, buf, l);
b->used += l;
}
isc_result_t
isc_buffer_dup(isc_mem_t *mctx, isc_buffer_t **dstp, const isc_buffer_t *src) {
isc_buffer_t *dst = NULL;
isc_region_t region;
isc_result_t result;
REQUIRE(dstp != NULL && *dstp == NULL);
REQUIRE(ISC_BUFFER_VALID(src));
isc_buffer_usedregion(src, &region);
isc_buffer_allocate(mctx, &dst, region.length);
result = isc_buffer_copyregion(dst, &region);
RUNTIME_CHECK(result == ISC_R_SUCCESS); /* NOSPACE is impossible */
*dstp = dst;
return (ISC_R_SUCCESS);
}
isc_result_t
isc_buffer_copyregion(isc_buffer_t *b, const isc_region_t *r) {
isc_result_t result;
REQUIRE(ISC_BUFFER_VALID(b));
REQUIRE(r != NULL);
if (b->autore) {
result = isc_buffer_reserve(&b, r->length);
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (r->length > isc_buffer_availablelength(b)) {
return (ISC_R_NOSPACE);
}
if (r->length > 0U) {
memmove(isc_buffer_used(b), r->base, r->length);
b->used += r->length;
}
return (ISC_R_SUCCESS);
}
void
isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
unsigned int length) {
REQUIRE(dynbuffer != NULL && *dynbuffer == NULL);
isc_buffer_t *dbuf = isc_mem_get(mctx, sizeof(isc_buffer_t));
unsigned char *bdata = isc_mem_get(mctx, length);
isc_buffer_init(dbuf, bdata, length);
ENSURE(ISC_BUFFER_VALID(dbuf));
dbuf->mctx = mctx;
*dynbuffer = dbuf;
}
isc_result_t
isc_buffer_reserve(isc_buffer_t **dynbuffer, unsigned int size) {
size_t len;
REQUIRE(dynbuffer != NULL);
REQUIRE(ISC_BUFFER_VALID(*dynbuffer));
len = (*dynbuffer)->length;
if ((len - (*dynbuffer)->used) >= size) {
return (ISC_R_SUCCESS);
}
if ((*dynbuffer)->mctx == NULL) {
return (ISC_R_NOSPACE);
}
/* Round to nearest buffer size increment */
len = size + (*dynbuffer)->used;
len = (len + ISC_BUFFER_INCR - 1 - ((len - 1) % ISC_BUFFER_INCR));
/* Cap at UINT_MAX */
if (len > UINT_MAX) {
len = UINT_MAX;
}
if ((len - (*dynbuffer)->used) < size) {
return (ISC_R_NOMEMORY);
}
(*dynbuffer)->base = isc_mem_reget((*dynbuffer)->mctx,
(*dynbuffer)->base,
(*dynbuffer)->length, len);
(*dynbuffer)->length = (unsigned int)len;
return (ISC_R_SUCCESS);
}
void
isc_buffer_free(isc_buffer_t **dynbuffer) {
isc_buffer_t *dbuf;
isc_mem_t *mctx;
REQUIRE(dynbuffer != NULL);
REQUIRE(ISC_BUFFER_VALID(*dynbuffer));
REQUIRE((*dynbuffer)->mctx != NULL);
dbuf = *dynbuffer;
*dynbuffer = NULL; /* destroy external reference */
mctx = dbuf->mctx;
dbuf->mctx = NULL;
isc_mem_put(mctx, dbuf->base, dbuf->length);
isc_buffer_invalidate(dbuf);
isc_mem_put(mctx, dbuf, sizeof(isc_buffer_t));
}
isc_result_t
isc_buffer_printf(isc_buffer_t *b, const char *format, ...) {
va_list ap;
int n;
isc_result_t result;
REQUIRE(ISC_BUFFER_VALID(b));
va_start(ap, format);
n = vsnprintf(NULL, 0, format, ap);
va_end(ap);
if (n < 0) {
return (ISC_R_FAILURE);
}
if (b->autore) {
result = isc_buffer_reserve(&b, n + 1);
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (isc_buffer_availablelength(b) < (unsigned int)n + 1) {
return (ISC_R_NOSPACE);
}
va_start(ap, format);
n = vsnprintf(isc_buffer_used(b), n + 1, format, ap);
va_end(ap);
if (n < 0) {
return (ISC_R_FAILURE);
}
b->used += n;
return (ISC_R_SUCCESS);
}

View file

@ -562,7 +562,6 @@ isc__httpd_sendreq_new(isc_httpd_t *httpd) {
*/
isc_buffer_allocate(req->mctx, &req->sendbuffer, HTTP_SENDLEN);
isc_buffer_clear(req->sendbuffer);
isc_buffer_setautorealloc(req->sendbuffer, true);
isc_buffer_initnull(&req->bodybuffer);

File diff suppressed because it is too large Load diff

View file

@ -164,3 +164,101 @@
#endif /* WORDS_BIGENDIAN */
#endif /* !htobe64 */
/*
* Macros to convert uint8_t arrays to integers.
*/
/* Low-Endian */
#define ISC_U16TO8_LE(p, v) \
(p)[0] = (uint8_t)((v)); \
(p)[1] = (uint8_t)((v) >> 8);
#define ISC_U8TO16_LE(p) (((uint16_t)((p)[0])) | ((uint16_t)((p)[1]) << 8))
#define ISC_U32TO8_LE(p, v) \
(p)[0] = (uint8_t)((v)); \
(p)[1] = (uint8_t)((v) >> 8); \
(p)[2] = (uint8_t)((v) >> 16); \
(p)[3] = (uint8_t)((v) >> 24);
#define ISC_U8TO32_LE(p) \
(((uint32_t)((p)[0])) | ((uint32_t)((p)[1]) << 8) | \
((uint32_t)((p)[2]) << 16) | ((uint32_t)((p)[3]) << 24))
#define ISC_U48TO8_LE(p, v) \
(p)[0] = (uint8_t)((v)); \
(p)[1] = (uint8_t)((v) >> 8); \
(p)[2] = (uint8_t)((v) >> 16); \
(p)[3] = (uint8_t)((v) >> 24); \
(p)[4] = (uint8_t)((v) >> 32); \
(p)[5] = (uint8_t)((v) >> 40);
#define ISC_U8TO48_LE(p) \
(((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) | \
((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) | \
((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40))
#define ISC_U64TO8_LE(p, v) \
(p)[0] = (uint8_t)((v)); \
(p)[1] = (uint8_t)((v) >> 8); \
(p)[2] = (uint8_t)((v) >> 16); \
(p)[3] = (uint8_t)((v) >> 24); \
(p)[4] = (uint8_t)((v) >> 32); \
(p)[5] = (uint8_t)((v) >> 40); \
(p)[6] = (uint8_t)((v) >> 48); \
(p)[7] = (uint8_t)((v) >> 56);
#define ISC_U8TO64_LE(p) \
(((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) | \
((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) | \
((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) | \
((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56))
/* Big-Endian */
#define ISC_U16TO8_BE(p, v) \
(p)[0] = (uint8_t)((v) >> 8); \
(p)[1] = (uint8_t)((v));
#define ISC_U8TO16_BE(p) (((uint16_t)((p)[0]) << 8) | ((uint16_t)((p)[1])))
#define ISC_U32TO8_BE(p, v) \
(p)[0] = (uint8_t)((v) >> 24); \
(p)[1] = (uint8_t)((v) >> 16); \
(p)[2] = (uint8_t)((v) >> 8); \
(p)[3] = (uint8_t)((v));
#define ISC_U8TO32_BE(p) \
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3])))
#define ISC_U48TO8_BE(p, v) \
(p)[0] = (uint8_t)((v) >> 40); \
(p)[1] = (uint8_t)((v) >> 32); \
(p)[2] = (uint8_t)((v) >> 24); \
(p)[3] = (uint8_t)((v) >> 16); \
(p)[4] = (uint8_t)((v) >> 8); \
(p)[5] = (uint8_t)((v));
#define ISC_U8TO48_BE(p) \
(((uint64_t)((p)[0]) << 40) | ((uint64_t)((p)[1]) << 32) | \
((uint64_t)((p)[2]) << 24) | ((uint64_t)((p)[3]) << 16) | \
((uint64_t)((p)[4]) << 8) | ((uint64_t)((p)[5])))
#define ISC_U64TO8_BE(p, v) \
(p)[0] = (uint8_t)((v) >> 56); \
(p)[1] = (uint8_t)((v) >> 48); \
(p)[2] = (uint8_t)((v) >> 40); \
(p)[3] = (uint8_t)((v) >> 32); \
(p)[4] = (uint8_t)((v) >> 24); \
(p)[5] = (uint8_t)((v) >> 16); \
(p)[6] = (uint8_t)((v) >> 8); \
(p)[7] = (uint8_t)((v));
#define ISC_U8TO64_BE(p) \
(((uint64_t)((p)[0]) << 56) | ((uint64_t)((p)[1]) << 48) | \
((uint64_t)((p)[2]) << 40) | ((uint64_t)((p)[3]) << 32) | \
((uint64_t)((p)[4]) << 24) | ((uint64_t)((p)[5]) << 16) | \
((uint64_t)((p)[6]) << 8) | ((uint64_t)((p)[7])))

View file

@ -443,7 +443,6 @@ new_http_cstream(isc_nmsocket_t *sock, http_cstream_t **streamp) {
isc_buffer_allocate(mctx, &stream->rbuf,
INITIAL_DNS_MESSAGE_BUFFER_SIZE);
isc_buffer_setautorealloc(stream->rbuf, true);
ISC_LIST_PREPEND(sock->h2.session->cstreams, stream, link);
*streamp = stream;
@ -1005,7 +1004,6 @@ http_readcb(isc_nmhandle_t *handle, isc_result_t result, isc_region_t *region,
if (session->buf == NULL) {
isc_buffer_allocate(session->mctx, &session->buf,
unread_size);
isc_buffer_setautorealloc(session->buf, true);
}
isc_buffer_putmem(session->buf, region->base + readlen,
unread_size);
@ -1121,8 +1119,6 @@ http_send_outgoing(isc_nm_http_session_t *session, isc_nmhandle_t *httphandle,
isc_buffer_allocate(session->mctx,
&session->pending_write_data,
INITIAL_DNS_MESSAGE_BUFFER_SIZE);
isc_buffer_setautorealloc(session->pending_write_data,
true);
}
isc_buffer_putmem(session->pending_write_data, data, pending);
total = new_total;
@ -1267,13 +1263,15 @@ http_do_bio(isc_nm_http_session_t *session, isc_nmhandle_t *send_httphandle,
if (nghttp2_session_want_read(session->ngsession) != 0) {
if (!session->reading) {
/* We have not yet started reading from this handle */
/* We have not yet started
* reading from this handle */
isc_nm_read(session->handle, http_readcb, session);
session->reading = true;
} else if (session->buf != NULL) {
size_t remaining =
isc_buffer_remaininglength(session->buf);
/* Leftover data in the buffer, use it */
/* Leftover data in the
* buffer, use it */
size_t readlen = nghttp2_session_mem_recv(
session->ngsession,
isc_buffer_current(session->buf), remaining);
@ -1288,7 +1286,9 @@ http_do_bio(isc_nm_http_session_t *session, isc_nmhandle_t *send_httphandle,
send_cbarg);
return;
} else {
/* Resume reading, it's idempotent, wait for more */
/* Resume reading, it's
* idempotent, wait for more
*/
isc_nm_read(session->handle, http_readcb, session);
}
} else {
@ -1406,9 +1406,10 @@ transport_connect_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
NGHTTP2_PROTO_VERSION_ID_LEN) != 0)
{
/*
* HTTP/2 negotiation error. Any sensible DoH
* client will fail if HTTP/2 cannot be
* negotiated via ALPN.
* HTTP/2 negotiation error.
* Any sensible DoH client
* will fail if HTTP/2 cannot
* be negotiated via ALPN.
*/
result = ISC_R_HTTP2ALPNERROR;
goto error;
@ -2346,9 +2347,12 @@ server_on_frame_recv_callback(nghttp2_session *ngsession,
ngsession, frame->hd.stream_id);
/*
* For DATA and HEADERS frame, this callback may be
* called after on_stream_close_callback. Check that
* the stream is still alive.
* For DATA and HEADERS frame,
* this callback may be called
* after
* on_stream_close_callback.
* Check that the stream is
* still alive.
*/
if (socket == NULL) {
return (0);
@ -3168,9 +3172,12 @@ isc__nm_base64_to_base64url(isc_mem_t *mem, const char *base64,
break;
default:
/*
* All other characters from the alphabet are the same
* for both base64 and base64url, so we can reuse the
* validation table for the rest of the characters.
* All other characters from
* the alphabet are the same
* for both base64 and
* base64url, so we can reuse
* the validation table for
* the rest of the characters.
*/
if (base64[i] != '-' && base64[i] != '_' &&
base64url_validation_table[(size_t)base64[i]])

View file

@ -67,29 +67,9 @@
#define HALFSIPROUND FULL_ROUND32
#define U32TO8_LE(p, v) \
(p)[0] = (uint8_t)((v)); \
(p)[1] = (uint8_t)((v) >> 8); \
(p)[2] = (uint8_t)((v) >> 16); \
(p)[3] = (uint8_t)((v) >> 24);
#define U8TO32_LE(p) \
(((uint32_t)((p)[0])) | ((uint32_t)((p)[1]) << 8) | \
((uint32_t)((p)[2]) << 16) | ((uint32_t)((p)[3]) << 24))
#define U8TO32_ONE(case_sensitive, byte) \
(uint32_t)(case_sensitive ? byte : isc__ascii_tolower1(byte))
#define U64TO8_LE(p, v) \
U32TO8_LE((p), (uint32_t)((v))); \
U32TO8_LE((p) + 4, (uint32_t)((v) >> 32));
#define U8TO64_LE(p) \
(((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) | \
((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) | \
((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) | \
((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56))
#define U8TO64_ONE(case_sensitive, byte) \
(uint64_t)(case_sensitive ? byte : isc__ascii_tolower1(byte))
@ -99,8 +79,8 @@ isc_siphash24(const uint8_t *k, const uint8_t *in, const size_t inlen,
REQUIRE(k != NULL);
REQUIRE(out != NULL);
uint64_t k0 = U8TO64_LE(k);
uint64_t k1 = U8TO64_LE(k + 8);
uint64_t k0 = ISC_U8TO64_LE(k);
uint64_t k1 = ISC_U8TO64_LE(k + 8);
uint64_t v0 = UINT64_C(0x736f6d6570736575) ^ k0;
uint64_t v1 = UINT64_C(0x646f72616e646f6d) ^ k1;
@ -113,8 +93,9 @@ isc_siphash24(const uint8_t *k, const uint8_t *in, const size_t inlen,
const size_t left = inlen & 7;
for (; in != end; in += 8) {
uint64_t m = case_sensitive ? U8TO64_LE(in)
: isc_ascii_tolower8(U8TO64_LE(in));
uint64_t m = case_sensitive
? ISC_U8TO64_LE(in)
: isc_ascii_tolower8(ISC_U8TO64_LE(in));
v3 ^= m;
@ -169,7 +150,7 @@ isc_siphash24(const uint8_t *k, const uint8_t *in, const size_t inlen,
b = v0 ^ v1 ^ v2 ^ v3;
U64TO8_LE(out, b);
ISC_U64TO8_LE(out, b);
}
void
@ -178,8 +159,8 @@ isc_halfsiphash24(const uint8_t *k, const uint8_t *in, const size_t inlen,
REQUIRE(k != NULL);
REQUIRE(out != NULL);
uint32_t k0 = U8TO32_LE(k);
uint32_t k1 = U8TO32_LE(k + 4);
uint32_t k0 = ISC_U8TO32_LE(k);
uint32_t k1 = ISC_U8TO32_LE(k + 4);
uint32_t v0 = UINT32_C(0x00000000) ^ k0;
uint32_t v1 = UINT32_C(0x00000000) ^ k1;
@ -192,8 +173,9 @@ isc_halfsiphash24(const uint8_t *k, const uint8_t *in, const size_t inlen,
const int left = inlen & 3;
for (; in != end; in += 4) {
uint32_t m = case_sensitive ? U8TO32_LE(in)
: isc_ascii_tolower4(U8TO32_LE(in));
uint32_t m = case_sensitive
? ISC_U8TO32_LE(in)
: isc_ascii_tolower4(ISC_U8TO32_LE(in));
v3 ^= m;
@ -235,5 +217,5 @@ isc_halfsiphash24(const uint8_t *k, const uint8_t *in, const size_t inlen,
}
b = v1 ^ v3;
U32TO8_LE(out, b);
ISC_U32TO8_LE(out, b);
}

View file

@ -113,14 +113,14 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) {
if (isccc_sexpr_binaryp(elt)) {
vr = isccc_sexpr_tobinary(elt);
len = REGION_SIZE(*vr);
result = isc_buffer_reserve(buffer, 1 + 4);
result = isc_buffer_reserve(*buffer, 1 + 4);
if (result != ISC_R_SUCCESS) {
return (ISC_R_NOSPACE);
}
isc_buffer_putuint8(*buffer, ISCCC_CCMSGTYPE_BINARYDATA);
isc_buffer_putuint32(*buffer, len);
result = isc_buffer_reserve(buffer, len);
result = isc_buffer_reserve(*buffer, len);
if (result != ISC_R_SUCCESS) {
return (ISC_R_NOSPACE);
}
@ -129,7 +129,7 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) {
unsigned int used;
isc_buffer_t b;
result = isc_buffer_reserve(buffer, 1 + 4);
result = isc_buffer_reserve(*buffer, 1 + 4);
if (result != ISC_R_SUCCESS) {
return (ISC_R_NOSPACE);
}
@ -163,7 +163,7 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) {
unsigned int used;
isc_buffer_t b;
result = isc_buffer_reserve(buffer, 1 + 4);
result = isc_buffer_reserve(*buffer, 1 + 4);
if (result != ISC_R_SUCCESS) {
return (ISC_R_NOSPACE);
}
@ -217,7 +217,7 @@ table_towire(isccc_sexpr_t *alist, isc_buffer_t **buffer) {
/*
* Emit the key name.
*/
result = isc_buffer_reserve(buffer, 1 + len);
result = isc_buffer_reserve(*buffer, 1 + len);
if (result != ISC_R_SUCCESS) {
return (ISC_R_NOSPACE);
}
@ -313,7 +313,7 @@ isccc_cc_towire(isccc_sexpr_t *alist, isc_buffer_t **buffer, uint32_t algorithm,
unsigned int hmac_base, signed_base;
isc_result_t result;
result = isc_buffer_reserve(buffer,
result = isc_buffer_reserve(*buffer,
4 + ((algorithm == ISCCC_ALG_HMACMD5)
? sizeof(auth_hmd5)
: sizeof(auth_hsha)));

View file

@ -1166,7 +1166,8 @@ compute_cookie(ns_client_t *client, uint32_t when, uint32_t nonce,
cp = isc_buffer_used(buf);
isc_buffer_putmem(buf, client->cookie, 8);
isc_buffer_putuint8(buf, NS_COOKIE_VERSION_1);
isc_buffer_putuint24(buf, 0); /* Reserved */
isc_buffer_putuint8(buf, 0); /* Reserved */
isc_buffer_putuint16(buf, 0); /* Reserved */
isc_buffer_putuint32(buf, when);
memmove(input, cp, 16);

View file

@ -42,48 +42,44 @@ ISC_RUN_TEST_IMPL(isc_buffer_reserve) {
UNUSED(state);
b = NULL;
isc_buffer_allocate(mctx, &b, 1024);
assert_int_equal(b->length, 1024);
isc_buffer_allocate(mctx, &b, ISC_BUFFER_INCR);
assert_int_equal(b->length, ISC_BUFFER_INCR);
/*
* 1024 bytes should already be available, so this call does
* 512 bytes should already be available, so this call does
* nothing.
*/
result = isc_buffer_reserve(&b, 1024);
result = isc_buffer_reserve(b, 512);
assert_int_equal(result, ISC_R_SUCCESS);
assert_true(ISC_BUFFER_VALID(b));
assert_non_null(b);
assert_int_equal(b->length, 1024);
assert_int_equal(b->length, ISC_BUFFER_INCR);
/*
* This call should grow it to 2048 bytes as only 1024 bytes are
* This call should grow it to 1536 bytes as only 1024 bytes are
* available in the buffer.
*/
result = isc_buffer_reserve(&b, 1025);
result = isc_buffer_reserve(b, 1025);
assert_int_equal(result, ISC_R_SUCCESS);
assert_true(ISC_BUFFER_VALID(b));
assert_non_null(b);
assert_int_equal(b->length, 2048);
assert_int_equal(b->length, 3 * ISC_BUFFER_INCR);
/*
* 2048 bytes should already be available, so this call does
* 1536 bytes should already be available, so this call does
* nothing.
*/
result = isc_buffer_reserve(&b, 2000);
result = isc_buffer_reserve(b, 1500);
assert_int_equal(result, ISC_R_SUCCESS);
assert_true(ISC_BUFFER_VALID(b));
assert_non_null(b);
assert_int_equal(b->length, 2048);
assert_int_equal(b->length, 3 * ISC_BUFFER_INCR);
/*
* This call should grow it to 4096 bytes as only 2048 bytes are
* This call should grow it to 4096 bytes as only 1536 bytes are
* available in the buffer.
*/
result = isc_buffer_reserve(&b, 3000);
result = isc_buffer_reserve(b, 3585);
assert_int_equal(result, ISC_R_SUCCESS);
assert_true(ISC_BUFFER_VALID(b));
assert_non_null(b);
assert_int_equal(b->length, 4096);
assert_int_equal(b->length, 8 * ISC_BUFFER_INCR);
/* Consume some of the buffer so we can run the next test. */
isc_buffer_add(b, 4096);
@ -91,11 +87,10 @@ ISC_RUN_TEST_IMPL(isc_buffer_reserve) {
/*
* This call should fail and leave buffer untouched.
*/
result = isc_buffer_reserve(&b, UINT_MAX);
result = isc_buffer_reserve(b, UINT_MAX);
assert_int_equal(result, ISC_R_NOMEMORY);
assert_true(ISC_BUFFER_VALID(b));
assert_non_null(b);
assert_int_equal(b->length, 4096);
assert_int_equal(b->length, 8 * ISC_BUFFER_INCR);
isc_buffer_free(&b);
}
@ -113,8 +108,6 @@ ISC_RUN_TEST_IMPL(isc_buffer_dynamic) {
assert_non_null(b);
assert_int_equal(b->length, last_length);
isc_buffer_setautorealloc(b, true);
isc_buffer_putuint8(b, 1);
for (i = 0; i < 1000; i++) {
@ -136,14 +129,6 @@ ISC_RUN_TEST_IMPL(isc_buffer_dynamic) {
assert_true(b->length - last_length >= 10000 * 2);
last_length += 10000 * 2;
for (i = 0; i < 10000; i++) {
isc_buffer_putuint24(b, 1);
}
assert_true(b->length - last_length >= 10000 * 3);
last_length += 10000 * 3;
for (i = 0; i < 10000; i++) {
isc_buffer_putuint32(b, 1);
}
@ -174,16 +159,9 @@ ISC_RUN_TEST_IMPL(isc_buffer_copyregion) {
assert_int_equal(result, ISC_R_SUCCESS);
/*
* Appending more data to the buffer should fail.
* Appending should succeed.
*/
result = isc_buffer_copyregion(b, &r);
assert_int_equal(result, ISC_R_NOSPACE);
/*
* Enable auto reallocation and retry. Appending should now succeed.
*/
isc_buffer_setautorealloc(b, true);
result = isc_buffer_copyregion(b, &r);
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_free(&b);
@ -204,7 +182,6 @@ ISC_RUN_TEST_IMPL(isc_buffer_printf) {
*/
b = NULL;
isc_buffer_allocate(mctx, &b, 0);
isc_buffer_setautorealloc(b, true);
/*
* Sanity check.