Commit fbe88ccd authored by Vladimír Čunát's avatar Vladimír Čunát

hints: change the handling of repeated hints (again)

In reverse (PTR) records, now the last definition wins,
and non-canonical names don't get (shadowed) records.
parent e87c31c1
......@@ -23,6 +23,8 @@
* backed by an array.
*
* @note Maximum object size is 2^16 bytes, see ::pack_objlen_t
* @TODO If some mistake happens somewhere, the access may end up in an infinite loop.
* (equality comparison on pointers)
*
* # Example usage:
*
......@@ -113,6 +115,23 @@ static inline uint8_t *pack_obj_next(uint8_t *it)
return pack_obj_val(it) + pack_obj_len(it);
}
/** Return pointer to the last packed object. */
static inline uint8_t *pack_last(pack_t pack)
{
if (pack.len == 0) {
return NULL;
}
uint8_t *it = pack_head(pack);
uint8_t *tail = pack_tail(pack);
while (true) {
uint8_t *next = pack_obj_next(it);
if (next == tail) {
return it;
}
it = next;
}
}
/** Push object to the end of the pack
* @return 0 on success, negative number on failure
*/
......
......@@ -83,7 +83,7 @@ static int satisfy_reverse(struct kr_zonecut *hints, knot_pkt_t *pkt, struct kr_
knot_rrset_init(&rr, qname, KNOT_RRTYPE_PTR, KNOT_CLASS_IN);
/* Append address records from hints */
uint8_t *addr = pack_head(*addr_set);
uint8_t *addr = pack_last(*addr_set);
if (addr != NULL) {
size_t len = pack_obj_len(addr);
void *addr_val = pack_obj_val(addr);
......@@ -334,8 +334,12 @@ static int load_map(struct hints_data *data, FILE *fp)
continue;
}
char *name_tok = strtok_r(NULL, " \t\n", &saveptr);
bool canonical_name = true;
while (name_tok != NULL) {
add_reverse_pair(&data->reverse_hints, name_tok, tok);
if (canonical_name) {
add_reverse_pair(&data->reverse_hints, name_tok, tok);
canonical_name = false;
}
if (add_pair(&data->hints, name_tok, tok) == 0) {
count += 1;
}
......
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