Commit c455e7a3 authored by Marek Vavruša's avatar Marek Vavruša

lib/rrmap: added record map ranking

parent 222dc761
......@@ -203,7 +203,7 @@ static void stash_glue(map_t *stash, knot_pkt_t *pkt, const knot_dname_t *ns_nam
!knot_dname_is_equal(rr->owner, ns_name)) {
continue;
}
kr_rrmap_add(stash, rr, pool);
kr_rrmap_add(stash, rr, KR_RANK_BAD, pool);
}
}
......@@ -214,7 +214,7 @@ static void stash_ds(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_ctx
for (unsigned i = 0; i < authority->count; ++i) {
const knot_rrset_t *rr = knot_pkt_rr(authority, i);
if (rr->type == KNOT_RRTYPE_DS || rr->type == KNOT_RRTYPE_RRSIG) {
kr_rrmap_add(stash, rr, pool);
kr_rrmap_add(stash, rr, KR_RANK_AUTH, pool);
}
}
}
......@@ -233,7 +233,7 @@ static int stash_authority(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash,
stash_glue(stash, pkt, knot_ns_name(&rr->rrs, 0), pool);
}
/* Stash record */
kr_rrmap_add(stash, rr, pool);
kr_rrmap_add(stash, rr, KR_RANK_NONAUTH, pool);
}
return kr_ok();
}
......@@ -250,7 +250,7 @@ static int stash_answer(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_
&& rr->type != KNOT_RRTYPE_RRSIG) {
continue;
}
kr_rrmap_add(stash, rr, pool);
kr_rrmap_add(stash, rr, KR_RANK_AUTH, pool);
/* Follow CNAME chain in current cut. */
if (rr->type == KNOT_RRTYPE_CNAME) {
const knot_dname_t *next_cname = knot_cname_name(&rr->rrs);
......
......@@ -91,7 +91,7 @@ static int validate_section(struct kr_query *qry, knot_pkt_t *answer,
if (section_id == KNOT_ANSWER && !knot_dname_in(qry->zone_cut.name, rr->owner)) {
continue;
}
ret = kr_rrmap_add(&stash, rr, pool);
ret = kr_rrmap_add(&stash, rr, 0, pool);
if (ret != 0) {
goto fail;
}
......
......@@ -264,10 +264,7 @@ int kr_bitcmp(const char *a, const char *b, int bits)
return ret;
}
/* Set stashed RR flag */
#define KEY_FLAG_SET(key, flag) key[0] = (flag);
int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool)
int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *pool)
{
if (!stash || !rr) {
return kr_error(EINVAL);
......@@ -276,13 +273,13 @@ int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool)
/* Stash key = {[1] flags, [1-255] owner, [1-5] type, [1] \x00 } */
char key[9 + KNOT_DNAME_MAXLEN];
uint16_t rrtype = rr->type;
KEY_FLAG_SET(key, KEY_FLAG_NO);
key[0] = (rank << 2) | 0x01; /* Must be non-zero */
/* Stash RRSIGs in a special cache, flag them and set type to its covering RR.
* This way it the stash won't merge RRSIGs together. */
if (rr->type == KNOT_RRTYPE_RRSIG) {
rrtype = knot_rrsig_type_covered(&rr->rrs, 0);
KEY_FLAG_SET(key, KEY_FLAG_RRSIG);
key[0] |= KEY_FLAG_RRSIG;
}
uint8_t *key_buf = (uint8_t *)key + 1;
......
......@@ -113,12 +113,12 @@ int kr_straddr_subnet(void *dst, const char *addr);
int kr_bitcmp(const char *a, const char *b, int bits);
/** @internal RR map flags. */
#define KEY_FLAG_NO 0x01
#define KEY_FLAG_RRSIG 0x02
#define KEY_FLAG_RANK(key) (key[0] >> 2)
#define KEY_COVERING_RRSIG(key) (key[0] & KEY_FLAG_RRSIG)
/** @internal Merges RRSets with matching owner name and type together.
* @note RRSIG RRSets are merged according the type covered fields.
* @return 0 or an error
*/
int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, mm_ctx_t *pool);
\ No newline at end of file
int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *pool);
\ No newline at end of file
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