Commit 5f77f213 authored by Štěpán Balážik's avatar Štěpán Balážik

WIP

parent 03a7c0be
Pipeline #66502 failed with stages
in 31 seconds
modules.unload('ta_update')
modules.unload('ta_signal_query')
modules.unload('priming')
modules.unload('detect_time_skew')
modules.unload('detect_time_jump')
modules.unload('ta_sentinel')
......
......@@ -994,7 +994,7 @@ static uv_handle_t *transmit(struct qr_task *task)
}
/* Checkout answer before sending it */
struct request_ctx *ctx = task->ctx;
if (kr_resolve_checkout(&ctx->req, NULL, (struct sockaddr *)choice, SOCK_DGRAM, task->pktbuf) != 0) {
if (kr_resolve_checkout(&ctx->req, NULL, transport, task->pktbuf) != 0) {
return ret;
}
ret = ioreq_spawn(ctx->worker, SOCK_DGRAM, choice->sin6_family, false);
......@@ -1359,8 +1359,7 @@ static int tcp_task_step(struct qr_task *task,
}
/* Checkout task before connecting */
struct request_ctx *ctx = task->ctx;
if (kr_resolve_checkout(&ctx->req, NULL, (struct sockaddr *)addr,
SOCK_STREAM, task->pktbuf) != 0) {
if (kr_resolve_checkout(&ctx->req, NULL, task->transport, task->pktbuf) != 0) {
subreq_finalize(task, packet_source, packet);
return qr_task_finalize(task, KR_STATE_FAIL);
}
......@@ -1726,12 +1725,9 @@ int worker_end_tcp(struct session *session)
return kr_ok();
}
knot_pkt_t * worker_resolve_mk_pkt(const char *qname_str, uint16_t qtype, uint16_t qclass,
knot_pkt_t *worker_resolve_mk_pkt_dname(knot_dname_t qname, uint16_t qtype, uint16_t qclass,
const struct kr_qflags *options)
{
uint8_t qname[KNOT_DNAME_MAXLEN];
if (!knot_dname_from_str(qname, qname_str, sizeof(qname)))
return NULL;
knot_pkt_t *pkt = knot_pkt_new(NULL, KNOT_EDNS_MAX_UDP_PAYLOAD, NULL);
if (!pkt)
return NULL;
......@@ -1766,6 +1762,15 @@ knot_pkt_t * worker_resolve_mk_pkt(const char *qname_str, uint16_t qtype, uint16
return pkt;
}
knot_pkt_t *worker_resolve_mk_pkt(const char *qname_str, uint16_t qtype, uint16_t qclass,
const struct kr_qflags *options)
{
uint8_t qname[KNOT_DNAME_MAXLEN];
if (!knot_dname_from_str(qname, qname_str, sizeof(qname)))
return NULL;
return worker_resolve_mk_pkt_dname(qname, qtype, qclass, options);
}
struct qr_task *worker_resolve_start(knot_pkt_t *query, struct kr_qflags options)
{
struct worker_ctx *worker = the_worker;
......
......@@ -44,6 +44,9 @@ int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt
*/
int worker_end_tcp(struct session *session);
knot_pkt_t *worker_resolve_mk_pkt_dname(knot_dname_t qname, uint16_t qtype, uint16_t qclass,
const struct kr_qflags *options);
/**
* Create a packet suitable for worker_resolve_start(). All in malloc() memory.
*/
......
......@@ -1061,11 +1061,12 @@ static int resolve(kr_layer_t *ctx, knot_pkt_t *pkt)
VERBOSE_MSG("<= truncated response, failover to TCP\n");
if (query) {
/* Fail if already on TCP. */
if (query->flags.TCP) {
if (req->upstream.transport->protocol != KR_TRANSPORT_UDP) {
VERBOSE_MSG("<= TC=1 with TCP, bailing out\n");
query->server_selection.error(query, req->upstream.transport, KR_SELECTION_TRUNCATED);
return resolve_error(pkt, req);
}
query->flags.TCP = true;
query->server_selection.error(query, req->upstream.transport, KR_SELECTION_TRUNCATED);
}
return KR_STATE_CONSUME;
}
......
......@@ -90,6 +90,14 @@ struct choice {
struct iter_address_state *address_state;
};
void async_ns_resolution(knot_dname_t *name, enum knot_rr_type type) {
struct kr_qflags flags;
memset(&flags, 0, sizeof(struct kr_qflags));
knot_pkt_t* pkt = worker_resolve_mk_pkt_dname(name, type, KNOT_CLASS_IN, &flags);
worker_resolve_start(pkt, flags);
free(pkt);
}
void iter_update_state_from_rtt_cache(struct iter_local_state *local_state, struct kr_cache *cache) {
trie_it_t *it;
for(it = trie_it_begin(local_state->addresses); !trie_it_finished(it); trie_it_next(it)) {
......
......@@ -17,6 +17,7 @@ enum kr_selection_error {
KR_SELECTION_FORMERROR,
KR_SELECTION_NOTIMPL,
KR_SELECTION_OTHER_RCODE,
KR_SELECTION_TRUNCATED,
KR_SELECTION_DNSSEC_ERROR,
......
......@@ -1318,9 +1318,20 @@ int kr_resolve_produce(struct kr_request *request, struct kr_transport **transpo
qry->server_selection.choose_transport(qry, transport);
if (*transport == NULL) {
// There is no point in continuing.
return KR_STATE_FAIL;
}
if ((*transport)->protocol == KR_TRANSPORT_NOADDR) {
ns_resolve_addr(qry, qry->request, *transport);
return KR_STATE_YIELD;
int ret = ns_resolve_addr(qry, qry->request, *transport);
if (ret) {
qry->flags.AWAIT_IPV4 = false;
qry->flags.AWAIT_IPV6 = false;
}
printf("ns_resolve_addr ret: %d\n", ret);
ITERATE_LAYERS(request, qry, reset);
return KR_STATE_PRODUCE;
}
/* Randomize query case (if not in safe mode or turned off) */
......@@ -1370,7 +1381,7 @@ static bool outbound_request_update_cookies(struct kr_request *req,
#endif /* defined(ENABLE_COOKIES) */
int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src,
struct sockaddr *dst, int type, knot_pkt_t *packet)
struct kr_transport *transport, knot_pkt_t *packet)
{
/* @todo: Update documentation if this function becomes approved. */
......@@ -1394,7 +1405,7 @@ int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src,
* actual cookie. If we don't know the server address then we
* also don't know the actual cookie size.
*/
if (!outbound_request_update_cookies(request, src, dst)) {
if (!outbound_request_update_cookies(request, src, &transport->address.ip)) {
return kr_error(EINVAL);
}
}
......@@ -1411,8 +1422,20 @@ int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src,
/* Run the checkout layers and cancel on failure.
* The checkout layer doesn't persist the state, so canceled subrequests
* don't affect the resolution or rest of the processing. */
int type = -1;
switch(transport->protocol) {
case KR_TRANSPORT_UDP:
type = SOCK_DGRAM;
break;
case KR_TRANSPORT_TCP:
case KR_TRANSPORT_TLS:
type = SOCK_PACKET;
break;
default:
assert(0);
}
int state = request->state;
ITERATE_LAYERS(request, qry, checkout, packet, dst, type);
ITERATE_LAYERS(request, qry, checkout, packet, &transport->address.ip, type);
if (request->state & KR_STATE_FAIL) {
request->state = state; /* Restore */
return kr_error(ECANCELED);
......@@ -1432,29 +1455,20 @@ int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src,
}
}
// WITH_VERBOSE(qry) {
// KR_DNAME_GET_STR(qname_str, knot_pkt_qname(packet));
// KR_DNAME_GET_STR(zonecut_str, qry->zone_cut.name);
// KR_RRTYPE_GET_STR(type_str, knot_pkt_qtype(packet));
// for (size_t i = 0; i < KR_NSREP_MAXADDR; ++i) {
// struct sockaddr *addr = &qry->ns.addr[i].ip;
// if (addr->sa_family == AF_UNSPEC) {
// break;
// }
// if (!kr_inaddr_equal(dst, addr)) {
// continue;
// }
// const char *ns_str = kr_straddr(addr);
// VERBOSE_MSG(qry,
// "=> id: '%05u' querying: '%s' score: %u zone cut: '%s' "
// "qname: '%s' qtype: '%s' proto: '%s'\n",
// qry->id, ns_str ? ns_str : "", qry->ns.score, zonecut_str,
// qname_str, type_str, (qry->flags.TCP) ? "tcp" : "udp");
// break;
// }}
WITH_VERBOSE(qry) {
KR_DNAME_GET_STR(qname_str, knot_pkt_qname(packet));
KR_DNAME_GET_STR(ns_name, transport->name);
KR_DNAME_GET_STR(zonecut_str, qry->zone_cut.name);
KR_RRTYPE_GET_STR(type_str, knot_pkt_qtype(packet));
const char *ns_str = kr_straddr(&transport->address.ip);
VERBOSE_MSG(qry,
"=> id: '%05u' querying: '%s'@'%s' zone cut: '%s' "
"qname: '%s' qtype: '%s' proto: '%s'\n",
qry->id, ns_name, ns_str ? ns_str : "", zonecut_str,
qname_str, type_str, (qry->flags.TCP) ? "tcp" : "udp");
}
return kr_ok();
}
......
......@@ -291,7 +291,7 @@ int kr_resolve_produce(struct kr_request *request, struct kr_transport **transpo
*/
KR_EXPORT
int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src,
struct sockaddr *dst, int type, knot_pkt_t *packet);
struct kr_transport *transport, knot_pkt_t *packet);
/**
* Finish resolution and commit results if the state is DONE.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment