...
 
Commits (2)
......@@ -440,7 +440,6 @@ static int init_resolver(struct engine *engine)
engine->resolver.negative_anchors = map_make(NULL);
engine->resolver.pool = engine->pool;
engine->resolver.modules = &engine->modules;
// NS_REP engine->resolver.cache_rtt_tout_retry_interval = KR_NS_TIMEOUT_RETRY_INTERVAL;
/* Create OPT RR */
engine->resolver.opt_rr = mm_alloc(engine->pool, sizeof(knot_rrset_t));
if (!engine->resolver.opt_rr) {
......@@ -451,10 +450,6 @@ static int init_resolver(struct engine *engine)
engine->resolver.tls_padding = -1;
/* Empty init; filled via ./lua/postconfig.lua */
kr_zonecut_init(&engine->resolver.root_hints, (const uint8_t *)"", engine->pool);
/* Open NS rtt + reputation cache */
// NS_REP
// lru_create(&engine->resolver.cache_rtt, LRU_RTT_SIZE, NULL, NULL);
// lru_create(&engine->resolver.cache_rep, LRU_REP_SIZE, NULL, NULL);
lru_create(&engine->resolver.cache_cookie, LRU_COOKIES_SIZE, NULL, NULL);
/* Load basic modules */
......@@ -640,9 +635,6 @@ void engine_deinit(struct engine *engine)
kr_cache_close(&engine->resolver.cache);
/* The LRUs are currently malloc-ated and need to be freed. */
// NS_REP
// lru_free(engine->resolver.cache_rtt);
// lru_free(engine->resolver.cache_rep);
lru_free(engine->resolver.cache_cookie);
network_deinit(&engine->net);
......
This diff is collapsed.
......@@ -93,6 +93,10 @@ int worker_del_tcp_connected(struct worker_ctx *worker,
const struct sockaddr *addr);
int worker_del_tcp_waiting(struct worker_ctx *worker,
const struct sockaddr* addr);
struct session* worker_find_tcp_waiting(struct worker_ctx *worker,
const struct sockaddr* addr);
struct session* worker_find_tcp_connected(struct worker_ctx *worker,
const struct sockaddr* addr);
knot_pkt_t *worker_task_get_pktbuf(const struct qr_task *task);
struct request_ctx *worker_task_get_request(struct qr_task *task);
......@@ -128,7 +132,7 @@ struct worker_stats {
/** @cond internal */
/** Number of request within timeout window. */
#define MAX_PENDING 4 //NS_REP KR_NSREP_MAXADDR
#define MAX_PENDING 4
/** Maximum response time from TCP upstream, milliseconds */
#define MAX_TCP_INACTIVITY (KR_RESOLVE_TIME_LIMIT + KR_CONN_RTT_MAX)
......
......@@ -772,13 +772,6 @@ static int process_answer(knot_pkt_t *pkt, struct kr_request *req)
if (query->flags.FORWARD) {
next->forward_flags.CNAME = true;
if (query->parent == NULL) {
// NS_REP
// state = kr_nsrep_copy_set(&next->ns, &query->ns);
// if (state != kr_ok()) {
// return KR_STATE_FAIL;
// }
}
}
next->cname_parent = query;
/* Want DNSSEC if and only if it's posible to secure
......@@ -1056,7 +1049,7 @@ static int resolve(kr_layer_t *ctx, knot_pkt_t *pkt)
} else if (!is_paired_to_query(pkt, query)) {
WITH_VERBOSE(query) {
const char *ns_str =
req->upstream.addr ? kr_straddr(req->upstream.addr) : "(internal)";
req->upstream.transport ? kr_straddr(&req->upstream.transport->address.ip) : "(internal)";
VERBOSE_MSG("<= ignoring mismatching response from %s\n",
ns_str ? ns_str : "(kr_straddr failed)");
}
......@@ -1089,24 +1082,38 @@ static int resolve(kr_layer_t *ctx, knot_pkt_t *pkt)
switch(knot_wire_get_rcode(pkt->wire)) {
case KNOT_RCODE_NOERROR:
case KNOT_RCODE_NXDOMAIN:
query->server_selection.success(query, req->upstream.transport);
break; /* OK */
case KNOT_RCODE_YXDOMAIN: /* Basically a successful answer; name just doesn't fit. */
query->server_selection.success(query, req->upstream.transport);
knot_wire_set_rcode(req->answer->wire, KNOT_RCODE_YXDOMAIN);
break;
case KNOT_RCODE_REFUSED:
if (query->flags.STUB) {
/* just pass answer through if in stub mode */
break;
}
query->server_selection.error(query, req->upstream.transport, KR_SELECTION_REFUSED);
VERBOSE_MSG("<= rcode: %s\n", rcode ? rcode->name : "??");
return resolve_badmsg(pkt, req, query);
case KNOT_RCODE_SERVFAIL:
if (query->flags.STUB) {
/* just pass answer through if in stub mode */
break;
}
/* fall through */
query->server_selection.error(query, req->upstream.transport, KR_SELECTION_SERVFAIL);
VERBOSE_MSG("<= rcode: %s\n", rcode ? rcode->name : "??");
return resolve_badmsg(pkt, req, query);
case KNOT_RCODE_FORMERR:
query->server_selection.error(query, req->upstream.transport, KR_SELECTION_FORMERROR);
VERBOSE_MSG("<= rcode: %s\n", rcode ? rcode->name : "??");
return resolve_badmsg(pkt, req, query);
case KNOT_RCODE_NOTIMPL:
query->server_selection.error(query, req->upstream.transport, KR_SELECTION_NOTIMPL);
VERBOSE_MSG("<= rcode: %s\n", rcode ? rcode->name : "??");
return resolve_notimpl(pkt, req, query);
default:
query->server_selection.error(query, req->upstream.transport, KR_SELECTION_OTHER_RCODE);
VERBOSE_MSG("<= rcode: %s\n", rcode ? rcode->name : "??");
return resolve_error(pkt, req);
}
......
......@@ -23,6 +23,7 @@
#include "lib/utils.h"
#include "lib/defines.h"
#include "lib/module.h"
#include "lib/nsrep.h"
#define VERBOSE_MSG(qry, ...) QRVERBOSE(qry, "vldr", __VA_ARGS__)
......@@ -349,7 +350,7 @@ static knot_rrset_t *update_ds(struct kr_zonecut *cut, const knot_pktsection_t *
return NULL;
}
}
return new_ds;
return new_ds;
}
static void mark_insecure_parents(const struct kr_query *qry)
......@@ -1192,11 +1193,22 @@ static int hide_bogus(kr_layer_t *ctx) {
return ctx->state;
}
static int validate_wrapper(kr_layer_t *ctx, knot_pkt_t *pkt) {
// Wrapper for now.
int ret = validate(ctx, pkt);
struct kr_request *req = ctx->req;
struct kr_query *qry = req->current_query;
if (ret & KR_STATE_FAIL && qry->flags.DNSSEC_BOGUS)
qry->server_selection.error(qry, req->upstream.transport, KR_SELECTION_DNSSEC_ERROR);
return ret;
}
/** Module implementation. */
int validate_init(struct kr_module *self)
{
static const kr_layer_api_t layer = {
.consume = &validate,
.consume = &validate_wrapper,
.answer_finalize = &hide_bogus,
};
self->layer = &layer;
......
This diff is collapsed.
......@@ -4,27 +4,48 @@
#pragma once
#include <netinet/in.h>
#include "lib/utils.h"
struct kr_nsrep
{
knot_dname_t* name;
union inaddr addr[4];
};
enum kr_selection_error {
KR_SELECTION_TIMEOUT,
KR_SELECTION_TLS_HANDSHAKE_FAILED,
KR_SELECTION_TCP_CONNECT_FAILED,
KR_SELECTION_TCP_CONNECT_TIMEOUT,
typedef struct kr_nsrep_rtt_lru
{
KR_SELECTION_REFUSED,
KR_SELECTION_SERVFAIL,
KR_SELECTION_FORMERROR,
KR_SELECTION_NOTIMPL,
KR_SELECTION_OTHER_RCODE,
} kr_nsrep_rtt_lru_t;
KR_SELECTION_DNSSEC_ERROR,
typedef struct kr_nsrep_lru {
};
} kr_nsrep_lru_t;
enum kr_transport_protocol {
KR_TRANSPORT_NOADDR = 0,
KR_TRANSPORT_UDP,
KR_TRANSPORT_TCP,
KR_TRANSPORT_TLS,
};
typedef struct kr_nsrep_rtt_lru_entry {
struct kr_transport {
knot_dname_t *name;
union inaddr address;
enum kr_transport_protocol protocol;
unsigned timeout;
};
struct kr_server_selection
{
void (*choose_transport)(struct kr_query *qry, struct kr_transport **transport);
void (*success)(struct kr_query *qry, const struct kr_transport *transport);
void (*update_rtt)(struct kr_query *qry, const struct kr_transport *transport, unsigned rtt);
void (*error)(struct kr_query *qry, const struct kr_transport *transport, enum kr_selection_error error);
} kr_nsrep_rtt_lru_entry_t;
void *local_state;
};
// Initialize server selection structure inside qry.
KR_EXPORT
int kr_nsrep_elect(struct kr_query *qry, struct kr_context *ctx);
void kr_server_selection_init(struct kr_query *qry);
This diff is collapsed.
......@@ -155,9 +155,7 @@ struct kr_context
map_t negative_anchors;
struct kr_zonecut root_hints;
struct kr_cache cache;
kr_nsrep_rtt_lru_t *cache_rtt;
unsigned cache_rtt_tout_retry_interval;
kr_nsrep_lru_t *cache_rep;
module_array_t *modules;
/* The cookie context structure should not be held within the cookies
* module because of better access. */
......@@ -202,7 +200,7 @@ struct kr_request {
} qsource;
struct {
unsigned rtt; /**< Current upstream RTT */
const struct sockaddr *addr; /**< Current upstream address */
const struct kr_transport *transport; /**< Current upstream transport */
} upstream; /**< Upstream information, valid only in consume() phase */
struct kr_qflags options;
int state;
......@@ -261,7 +259,7 @@ int kr_resolve_begin(struct kr_request *request, struct kr_context *ctx, knot_pk
* @return any state
*/
KR_EXPORT
int kr_resolve_consume(struct kr_request *request, const struct sockaddr *src, knot_pkt_t *packet);
int kr_resolve_consume(struct kr_request *request, struct kr_transport **transport, knot_pkt_t *packet);
/**
* Produce either next additional query or finish.
......@@ -277,7 +275,7 @@ int kr_resolve_consume(struct kr_request *request, const struct sockaddr *src, k
* @return any state
*/
KR_EXPORT
int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *type, knot_pkt_t *packet);
int kr_resolve_produce(struct kr_request *request, struct kr_transport **transport, knot_pkt_t *packet);
/**
* Finalises the outbound query packet with the knowledge of the IP addresses.
......@@ -308,9 +306,6 @@ int kr_resolve_checkout(struct kr_request *request, const struct sockaddr *src,
KR_EXPORT
int kr_resolve_finish(struct kr_request *request, int state);
KR_EXPORT
int kr_ns_resolve_addr(struct kr_query *qry, struct kr_request *param);
/**
* Return resolution plan.
* @param request request state
......
......@@ -159,23 +159,13 @@ static struct kr_query *kr_rplan_push_query(struct kr_rplan *rplan,
qry->flags = rplan->request->options;
qry->parent = parent;
qry->request = rplan->request;
// NSREP: qry->ns.ctx = rplan->request->ctx;
// NSREP: qry->ns.addr[0].ip.sa_family = AF_UNSPEC;
gettimeofday(&qry->timestamp, NULL);
qry->timestamp_mono = kr_now();
qry->creation_time_mono = parent ? parent->creation_time_mono : qry->timestamp_mono;
kr_zonecut_init(&qry->zone_cut, (const uint8_t *)"", rplan->pool);
qry->reorder = qry->flags.REORDER_RR ? kr_rand_bytes(sizeof(qry->reorder)) : 0;
/* When forwarding, keep the nameserver addresses. */
// NS_REP
// if (parent && parent->flags.FORWARD && qry->flags.FORWARD) {
// ret = kr_nsrep_copy_set(&qry->ns, &parent->ns);
// if (ret) {
// query_free(rplan->pool, qry);
// return NULL;
// }
// }
assert((rplan->pending.len == 0 && rplan->resolved.len == 0)
== (rplan->initial == NULL));
......
......@@ -8,9 +8,9 @@
#include <libknot/dname.h>
#include <libknot/codes.h>
#include "lib/nsrep.h"
#include "lib/cache/api.h"
#include "lib/zonecut.h"
#include "lib/nsrep.h"
/** Query flags */
struct kr_qflags {
......@@ -101,8 +101,7 @@ struct kr_query {
struct kr_query *cname_parent;
struct kr_request *request; /**< Parent resolution request. */
kr_stale_cb stale_cb; /**< See the type */
/* Beware: this must remain the last, because of lua bindings. */
struct kr_nsrep ns;
struct kr_server_selection server_selection;
};
/** @cond internal Array of queries. */
......
......@@ -117,6 +117,7 @@ static inline void free_const(const void *what)
free((void *)what);
}
// Use this for alocations with mm.
static inline void *mm_alloc(knot_mm_t *mm, size_t size)
{
if (mm) return mm->alloc(mm->ctx, size);
......@@ -136,6 +137,7 @@ KR_EXPORT
void *mm_realloc(knot_mm_t *mm, void *what, size_t size, size_t prev_size);
/** Trivial malloc() wrapper. */
// Use mm_alloc for alocations into mempool
void *mm_malloc(void *ctx, size_t n);
/** posix_memalign() wrapper. */
void *mm_malloc_aligned(void *ctx, size_t n);
......
......@@ -337,18 +337,8 @@ static addrset_info_t fetch_addr(pack_t *addrs, const knot_dname_t *ns, uint16_t
(int)rd->len, (int)rrtype);
continue;
}
/* Check RTT cache - whether the IP is usable or not. */
// NS_REP
// kr_nsrep_rtt_lru_entry_t *rtt_e = ctx->cache_rtt
// ? lru_get_try(ctx->cache_rtt, (const char *)rd->data, rd->len)
// : NULL;
// const bool unusable = rtt_e && rtt_e->score >= KR_NS_TIMEOUT
// && qry->creation_time_mono
// < rtt_e->tout_timestamp + ctx->cache_rtt_tout_retry_interval;
// if (!unusable) {
// result = AI_OK;
// ++usable_cnt;
// }
result = AI_OK;
++usable_cnt;
ret = pack_obj_push(addrs, rd->data, rd->len);
assert(!ret); /* didn't fit because of incorrectly reserved memory */
......@@ -414,17 +404,8 @@ static int fetch_ns(struct kr_context *ctx, struct kr_zonecut *cut,
pack_init(**pack);
addrset_info_t infos[2];
/* Fetch NS reputation and decide whether to prefetch A/AAAA records. */
// NS_REP
// unsigned *cached = lru_get_try(ctx->cache_rep,
// (const char *)ns_name, ns_size);
// unsigned reputation = (cached) ? *cached : 0;
// infos[0] = (reputation & KR_NS_NOIP4) || qry->flags.NO_IPV4
// ? AI_REPUT
// : fetch_addr(*pack, ns_name, KNOT_RRTYPE_A, cut->pool, qry);
// infos[1] = (reputation & KR_NS_NOIP6) || qry->flags.NO_IPV6
// ? AI_REPUT
// : fetch_addr(*pack, ns_name, KNOT_RRTYPE_AAAA, cut->pool, qry);
infos[0] = fetch_addr(*pack, ns_name, KNOT_RRTYPE_A, cut->pool, qry);
infos[1] = fetch_addr(*pack, ns_name, KNOT_RRTYPE_AAAA, cut->pool, qry);
......
......@@ -147,7 +147,7 @@ static int collect_rtt(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *req = ctx->req;
struct kr_query *qry = req->current_query;
if (qry->flags.CACHED || !req->upstream.addr) {
if (qry->flags.CACHED || !req->upstream.transport) {
return ctx->state;
}
......@@ -158,7 +158,7 @@ static int collect_rtt(kr_layer_t *ctx, knot_pkt_t *pkt)
/* Socket address is encoded into sockaddr_in6 struct that
* unions with sockaddr_in and differ in sa_family */
struct sockaddr_in6 *e = &data->upstreams.q.at[data->upstreams.head];
const struct sockaddr *src = req->upstream.addr;
const struct sockaddr *src = &req->upstream.transport->address.ip;
switch (src->sa_family) {
case AF_INET: memcpy(e, src, sizeof(struct sockaddr_in)); break;
case AF_INET6: memcpy(e, src, sizeof(struct sockaddr_in6)); break;
......
......@@ -8,7 +8,7 @@ if get_option('unit_tests') != 'disabled'
cmocka = dependency('cmocka', required: get_option('unit_tests') == 'enabled')
if cmocka.found()
build_unit_tests = true
subdir('unit')
# subdir('unit')
endif
message('-------------------------------')
endif
......
......@@ -4,5 +4,5 @@
build_utils = get_option('utils') != 'disabled'
subdir('client')
subdir('cache_gc')
# subdir('cache_gc')
subdir('upgrade')