/* Unlocked. */
unsigned int magic; /*%< magic */
uint32_t tid;
+ isc_socktype_t socktype;
+ isc_refcount_t references;
isc_mem_t *mctx;
dns_dispatchmgr_t *mgr; /*%< dispatch manager */
isc_nmhandle_t *handle; /*%< netmgr handle for TCP connection */
isc_sockaddr_t local; /*%< local address */
- in_port_t localport; /*%< local UDP port */
isc_sockaddr_t peer; /*%< peer address (TCP) */
- isc_socktype_t socktype;
dns_dispatchstate_t state;
- isc_refcount_t references;
bool reading;
#define RESPONSE_MAGIC ISC_MAGIC('D', 'r', 's', 'p')
#define VALID_RESPONSE(e) ISC_MAGIC_VALID((e), RESPONSE_MAGIC)
-#define DISPSOCK_MAGIC ISC_MAGIC('D', 's', 'o', 'c')
-#define VALID_DISPSOCK(e) ISC_MAGIC_VALID((e), DISPSOCK_MAGIC)
-
#define DISPATCH_MAGIC ISC_MAGIC('D', 'i', 's', 'p')
#define VALID_DISPATCH(e) ISC_MAGIC_VALID((e), DISPATCH_MAGIC)
static void
udp_dispatch_getnext(dns_dispentry_t *resp, int32_t timeout);
-#define LVL(x) ISC_LOG_DEBUG(x)
-
static const char *
socktype2str(dns_dispentry_t *resp) {
dns_transport_type_t transport_type = DNS_TRANSPORT_UDP;
INSIST(!ISC_LINK_LINKED(resp, alink));
INSIST(!ISC_LINK_LINKED(resp, rlink));
- dispentry_log(resp, LVL(90), "destroying");
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "destroying");
if (resp->handle != NULL) {
- dispentry_log(resp, LVL(90), "detaching handle %p from %p",
- resp->handle, &resp->handle);
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
+ "detaching handle %p from %p", resp->handle,
+ &resp->handle);
isc_nmhandle_detach(&resp->handle);
}
eresult = ISC_R_CANCELED;
}
- dispentry_log(resp, LVL(90), "read callback:%s, requests %" PRIuFAST32,
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
+ "read callback:%s, requests %" PRIuFAST32,
isc_result_totext(eresult), disp->requests);
if (eresult != ISC_R_SUCCESS) {
NULL) == ISC_R_SUCCESS &&
match > 0)
{
- if (isc_log_wouldlog(dns_lctx, LVL(10))) {
+ if (isc_log_wouldlog(dns_lctx, ISC_LOG_DEBUG(10))) {
char netaddrstr[ISC_NETADDR_FORMATSIZE];
isc_netaddr_format(&netaddr, netaddrstr,
sizeof(netaddrstr));
- dispentry_log(resp, LVL(10),
+ dispentry_log(resp, ISC_LOG_DEBUG(10),
"blackholed packet from %s", netaddrstr);
}
goto next;
if (dres != ISC_R_SUCCESS) {
char netaddrstr[ISC_NETADDR_FORMATSIZE];
isc_netaddr_format(&netaddr, netaddrstr, sizeof(netaddrstr));
- dispentry_log(resp, LVL(10), "got garbage packet from %s",
- netaddrstr);
+ dispentry_log(resp, ISC_LOG_DEBUG(10),
+ "got garbage packet from %s", netaddrstr);
goto next;
}
- dispentry_log(resp, LVL(92),
+ dispentry_log(resp, ISC_LOG_DEBUG(92),
"got valid DNS message header, /QR %c, id %u",
(((flags & DNS_MESSAGEFLAG_QR) != 0) ? '1' : '0'), id);
* The QID and the address must match the expected ones.
*/
if (resp->id != id || !isc_sockaddr_equal(&peer, &resp->peer)) {
- dispentry_log(resp, LVL(90), "response doesn't match");
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
+ "response doesn't match");
inc_stats(disp->mgr, dns_resstatscounter_mismatch);
goto next;
}
done:
if (respond) {
- dispentry_log(resp, LVL(90), "UDP read callback on %p: %s",
- handle, isc_result_totext(eresult));
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
+ "UDP read callback on %p: %s", handle,
+ isc_result_totext(eresult));
resp->response(eresult, region, resp->arg);
}
unsigned int flags;
isc_result_t result = ISC_R_SUCCESS;
- dispatch_log(disp, LVL(90), "TCP read success, length == %d, addr = %p",
+ dispatch_log(disp, ISC_LOG_DEBUG(90),
+ "TCP read success, length == %d, addr = %p",
region->length, region->base);
/*
isc_buffer_add(&source, region->length);
result = dns_message_peekheader(&source, &id, &flags);
if (result != ISC_R_SUCCESS) {
- dispatch_log(disp, LVL(10), "got garbage packet");
+ dispatch_log(disp, ISC_LOG_DEBUG(10), "got garbage packet");
return (ISC_R_UNEXPECTED);
}
- dispatch_log(disp, LVL(92),
+ dispatch_log(disp, ISC_LOG_DEBUG(92),
"got valid DNS message header, /QR %c, id %u",
(((flags & DNS_MESSAGEFLAG_QR) != 0) ? '1' : '0'), id);
* reading.
*/
if ((flags & DNS_MESSAGEFLAG_QR) == 0) {
- dispatch_log(disp, LVL(10), "got DNS query instead of answer");
+ dispatch_log(disp, ISC_LOG_DEBUG(10),
+ "got DNS query instead of answer");
return (ISC_R_UNEXPECTED);
}
dns_dispentry_t key = {
.id = id,
.peer = *peer,
- .port = disp->localport,
+ .port = isc_sockaddr_getport(&disp->local),
};
struct cds_lfht_iter iter;
cds_lfht_lookup(disp->mgr->qids, qid_hash(&key), qid_match, &key,
} else {
result = ISC_R_NOTFOUND;
}
- dispatch_log(disp, LVL(90), "search for response in hashtable: %s",
+ dispatch_log(disp, ISC_LOG_DEBUG(90),
+ "search for response in hashtable: %s",
isc_result_totext(result));
return (result);
next = ISC_LIST_NEXT(resp, rlink);
ISC_LIST_UNLINK(*resps, resp, rlink);
- dispentry_log(resp, LVL(90), "read callback: %s",
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "read callback: %s",
isc_result_totext(resp->result));
resp->response(resp->result, region, resp->arg);
dns_dispentry_detach(&resp); /* DISPENTRY009 */
INSIST(disp->reading);
disp->reading = false;
- dispatch_log(disp, LVL(90), "TCP read:%s:requests %" PRIuFAST32,
+ dispatch_log(disp, ISC_LOG_DEBUG(90),
+ "TCP read:%s:requests %" PRIuFAST32,
isc_result_totext(result), disp->requests);
peer = isc_nmhandle_peeraddr(handle);
case ISC_R_EOF:
case ISC_R_CONNECTIONRESET:
isc_sockaddr_format(&peer, buf, sizeof(buf));
- dispatch_log(disp, LVL(90), "shutting down TCP: %s: %s", buf,
+ dispatch_log(disp, ISC_LOG_DEBUG(90),
+ "shutting down TCP: %s: %s", buf,
isc_result_totext(result));
tcp_recv_shutdown(disp, &resps, result);
break;
isc_sockaddr_format(&disp->local, addrbuf,
ISC_SOCKADDR_FORMATSIZE);
- mgr_log(mgr, LVL(90),
+ mgr_log(mgr, ISC_LOG_DEBUG(90),
"dns_dispatch_createtcp: created TCP dispatch %p for "
"%s",
disp, addrbuf);
isc_sockaddr_format(localaddr, addrbuf,
ISC_SOCKADDR_FORMATSIZE);
- mgr_log(mgr, LVL(90),
+ mgr_log(mgr, ISC_LOG_DEBUG(90),
"dispatch_createudp: created UDP dispatch %p for %s",
disp, addrbuf);
}
INSIST(ISC_LIST_EMPTY(disp->pending));
INSIST(ISC_LIST_EMPTY(disp->active));
- dispatch_log(disp, LVL(90), "destroying dispatch %p", disp);
+ dispatch_log(disp, ISC_LOG_DEBUG(90), "destroying dispatch %p", disp);
if (disp->handle) {
- dispatch_log(disp, LVL(90), "detaching TCP handle %p from %p",
- disp->handle, &disp->handle);
+ dispatch_log(disp, ISC_LOG_DEBUG(90),
+ "detaching TCP handle %p from %p", disp->handle,
+ &disp->handle);
isc_nmhandle_detach(&disp->handle);
}
dns_dispatchmgr_detach(&disp->mgr);
dispatch_cb_t connected, dispatch_cb_t sent,
dispatch_cb_t response, void *arg, dns_messageid_t *idp,
dns_dispentry_t **respp) {
- dns_dispentry_t *resp = NULL;
- in_port_t localport;
- int i = 0;
- isc_result_t result = ISC_R_UNSET;
-
REQUIRE(VALID_DISPATCH(disp));
REQUIRE(dest != NULL);
REQUIRE(respp != NULL && *respp == NULL);
REQUIRE(response != NULL);
REQUIRE(sent != NULL);
REQUIRE(loop != NULL);
-
REQUIRE(disp->tid == isc_tid());
if (disp->state == DNS_DISPATCHSTATE_CANCELED) {
return (ISC_R_CANCELED);
}
- localport = isc_sockaddr_getport(&disp->local);
-
- resp = isc_mem_get(disp->mctx, sizeof(*resp));
+ in_port_t localport = isc_sockaddr_getport(&disp->local);
+ dns_dispentry_t *resp = isc_mem_get(disp->mctx, sizeof(*resp));
*resp = (dns_dispentry_t){
- .port = localport,
.timeout = timeout,
.peer = *dest,
.loop = loop,
isc_refcount_init(&resp->references, 1); /* DISPENTRY000 */
if (disp->socktype == isc_socktype_udp) {
- result = setup_socket(disp, resp, dest, &localport);
+ isc_result_t result = setup_socket(disp, resp, dest,
+ &localport);
if (result != ISC_R_SUCCESS) {
isc_mem_put(disp->mctx, resp, sizeof(*resp));
inc_stats(disp->mgr, dns_resstatscounter_dispsockfail);
}
}
+ isc_result_t result = ISC_R_NOMORE;
+ size_t i = 0;
rcu_read_lock();
do {
/*
qid_match, resp, &resp->ht_node);
if (node != &resp->ht_node) {
- result = ISC_R_EXISTS;
if ((options & DNS_DISPATCHOPT_FIXEDID) != 0) {
/*
* When using fixed ID, we either must
fail:
if (result != ISC_R_SUCCESS) {
isc_mem_put(disp->mctx, resp, sizeof(*resp));
- return (ISC_R_NOMORE);
+ return (result);
}
isc_mem_attach(disp->mctx, &resp->mctx);
isc_result_t result = ISC_R_SUCCESS;
int32_t timeout = -1;
- dispentry_log(resp, LVL(90), "getnext for QID %d", resp->id);
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "getnext for QID %d", resp->id);
isc_time_t now = isc_loop_now(resp->loop);
timeout = resp->timeout - dispentry_runtime(resp, &now);
bool respond = false;
REQUIRE(disp->tid == isc_tid());
- dispentry_log(resp, LVL(90),
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
"canceling response: %s, %s/%s (%s/%s), "
"requests %" PRIuFAST32,
isc_result_totext(result), state2str(resp->state),
case DNS_DISPATCHSTATE_CONNECTED:
if (resp->reading) {
respond = true;
- dispentry_log(resp, LVL(90), "canceling read on %p",
- resp->handle);
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
+ "canceling read on %p", resp->handle);
isc_nm_cancelread(resp->handle);
}
break;
unlock:
if (respond) {
- dispentry_log(resp, LVL(90), "read callback: %s",
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "read callback: %s",
isc_result_totext(result));
resp->response(result, NULL, resp->arg);
}
dns_displist_t resps = ISC_LIST_INITIALIZER;
REQUIRE(disp->tid == isc_tid());
- dispentry_log(resp, LVL(90),
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
"canceling response: %s, %s/%s (%s/%s), "
"requests %" PRIuFAST32,
isc_result_totext(result), state2str(resp->state),
isc_nmhandle_settimeout(disp->handle, 1000);
if (!disp->reading) {
- dispentry_log(resp, LVL(90),
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
"final 1 second timeout on %p",
disp->handle);
tcp_startrecv(disp, NULL);
}
#else
if (disp->reading) {
- dispentry_log(resp, LVL(90),
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
"canceling read on %p",
disp->handle);
isc_nm_cancelread(disp->handle);
udp_startrecv(isc_nmhandle_t *handle, dns_dispentry_t *resp) {
REQUIRE(VALID_RESPONSE(resp));
- dispentry_log(resp, LVL(90), "attaching handle %p to %p", handle,
- &resp->handle);
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "attaching handle %p to %p",
+ handle, &resp->handle);
isc_nmhandle_attach(handle, &resp->handle);
dns_dispentry_ref(resp); /* DISPENTRY003 */
- dispentry_log(resp, LVL(90), "reading");
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "reading");
isc_nm_read(resp->handle, udp_recv, resp);
resp->reading = true;
}
dns_dispatch_ref(disp); /* DISPATCH002 */
if (resp != NULL) {
- dispentry_log(resp, LVL(90), "reading from %p", disp->handle);
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "reading from %p",
+ disp->handle);
INSIST(!isc_time_isepoch(&resp->start));
} else {
- dispatch_log(disp, LVL(90),
+ dispatch_log(disp, ISC_LOG_DEBUG(90),
"TCP reading without response from %p",
disp->handle);
}
ISC_SOCKADDR_FORMATSIZE);
}
- dispatch_log(disp, LVL(90), "connected from %s to %s: %s",
- localbuf, peerbuf, isc_result_totext(eresult));
+ dispatch_log(disp, ISC_LOG_DEBUG(90),
+ "connected from %s to %s: %s", localbuf, peerbuf,
+ isc_result_totext(eresult));
}
REQUIRE(disp->tid == isc_tid());
resp->state = DNS_DISPATCHSTATE_CONNECTED;
ISC_LIST_APPEND(disp->active, resp, alink);
resp->reading = true;
- dispentry_log(resp, LVL(90), "start reading");
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "start reading");
} else {
resp->state = DNS_DISPATCHSTATE_NONE;
}
next = ISC_LIST_NEXT(resp, rlink);
ISC_LIST_UNLINK(resps, resp, rlink);
- dispentry_log(resp, LVL(90), "connect callback: %s",
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "connect callback: %s",
isc_result_totext(resp->result));
resp->connected(resp->result, NULL, resp->arg);
dns_dispentry_detach(&resp); /* DISPENTRY005 */
dns_dispentry_t *resp = (dns_dispentry_t *)arg;
dns_dispatch_t *disp = resp->disp;
- dispentry_log(resp, LVL(90), "connected: %s",
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "connected: %s",
isc_result_totext(eresult));
REQUIRE(disp->tid == isc_tid());
}
unlock:
- dispentry_log(resp, LVL(90), "connect callback: %s",
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "connect callback: %s",
isc_result_totext(eresult));
resp->connected(eresult, NULL, resp->arg);
ISC_SOCKADDR_FORMATSIZE);
dns_dispatch_ref(disp); /* DISPATCH003 */
- dispentry_log(resp, LVL(90),
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
"connecting from %s to %s, timeout %u", localbuf,
peerbuf, resp->timeout);
/* Add the resp to the reading list */
ISC_LIST_APPEND(disp->active, resp, alink);
- dispentry_log(resp, LVL(90), "already connected; attaching");
+ dispentry_log(resp, ISC_LOG_DEBUG(90),
+ "already connected; attaching");
resp->reading = true;
if (!disp->reading) {
}
/* We are already connected; call the connected cb */
- dispentry_log(resp, LVL(90), "connect callback: %s",
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "connect callback: %s",
isc_result_totext(ISC_R_SUCCESS));
resp->connected(ISC_R_SUCCESS, NULL, resp->arg);
break;
REQUIRE(VALID_DISPATCH(disp));
- dispentry_log(resp, LVL(90), "sent: %s", isc_result_totext(result));
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "sent: %s",
+ isc_result_totext(result));
resp->sent(result, NULL, resp->arg);
int32_t timeout) {
REQUIRE(timeout <= INT16_MAX);
- dispentry_log(resp, LVL(90), "continue reading");
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "continue reading");
if (!resp->reading) {
ISC_LIST_APPEND(disp->active, resp, alink);
isc_nmhandle_settimeout(resp->handle, timeout);
}
- dispentry_log(resp, LVL(90), "continue reading");
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "continue reading");
dns_dispentry_ref(resp); /* DISPENTRY003 */
isc_nm_read(resp->handle, udp_recv, resp);
dns_dispatch_t *disp = resp->disp;
- dispentry_log(resp, LVL(90), "resume");
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "resume");
REQUIRE(disp->tid == isc_tid());
switch (disp->socktype) {
dns_dispatch_t *disp = resp->disp;
isc_nmhandle_t *sendhandle = NULL;
- dispentry_log(resp, LVL(90), "sending");
+ dispentry_log(resp, ISC_LOG_DEBUG(90), "sending");
switch (disp->socktype) {
case isc_socktype_udp:
isc_nmhandle_attach(resp->handle, &sendhandle);