/**
 * Store potential poison in the cache (only if hardening disabled).
 * The rrset is stored in the cache but removed from the message.
 * So that it will be used for infrastructure purposes, but not be
 * returned to the client.
 * @param pkt: packet
 * @param msg: message parsed
 * @param env: environment with cache
 * @param rrset: to store.
 */
static void
store_rrset(ldns_buffer* pkt, struct msg_parse* msg, struct module_env* env,
            struct rrset_parse* rrset)
{
    struct ub_packed_rrset_key* k;
    struct packed_rrset_data* d;
    struct rrset_ref ref;
    uint32_t now = *env->now;

    k = alloc_special_obtain(env->alloc);
    if(!k)
        return;
    k->entry.data = NULL;
    if(!parse_copy_decompress_rrset(pkt, msg, rrset, NULL, k)) {
        alloc_special_release(env->alloc, k);
        return;
    }
    d = (struct packed_rrset_data*)k->entry.data;
    packed_rrset_ttl_add(d, now);
    ref.key = k;
    ref.id = k->id;
    /*ignore ret: it was in the cache, ref updated */
    (void)rrset_cache_update(env->rrset_cache, &ref,
                             env->alloc, now);
}
Exemplo n.º 2
0
/** 
 * Copy and decompress rrs
 * @param pkt: the packet for compression pointer resolution.
 * @param msg: the parsed message
 * @param rep: reply info to put rrs into.
 * @param region: if not NULL, used for allocation.
 * @return 0 on failure.
 */
static int
parse_copy_decompress(sldns_buffer* pkt, struct msg_parse* msg,
	struct reply_info* rep, struct regional* region)
{
	size_t i;
	struct rrset_parse *pset = msg->rrset_first;
	struct packed_rrset_data* data;
	log_assert(rep);
	rep->ttl = MAX_TTL;
	rep->security = sec_status_unchecked;
	if(rep->rrset_count == 0)
		rep->ttl = NORR_TTL;

	for(i=0; i<rep->rrset_count; i++) {
		if(!parse_copy_decompress_rrset(pkt, msg, pset, region,
			rep->rrsets[i]))
			return 0;
		data = (struct packed_rrset_data*)rep->rrsets[i]->entry.data;
		if(data->ttl < rep->ttl)
			rep->ttl = data->ttl;

		pset = pset->rrset_all_next;
	}
	rep->prefetch_ttl = PREFETCH_TTL_CALC(rep->ttl);
	return 1;
}