generate_keytag_query(struct module_qstate* qstate, int id,
	struct trust_anchor* ta)
{
	/* 3 bytes for "_ta", 5 bytes per tag (4 bytes + "-") */
#define MAX_LABEL_TAGS (LDNS_MAX_LABELLEN-3)/5
	size_t i, numtag;
	uint16_t tags[MAX_LABEL_TAGS];
	char tagstr[LDNS_MAX_LABELLEN+1] = "_ta"; /* +1 for NULL byte */
	size_t tagstr_left = sizeof(tagstr) - strlen(tagstr);
	char* tagstr_pos = tagstr + strlen(tagstr);
	uint8_t dnamebuf[LDNS_MAX_DOMAINLEN+1]; /* +1 for label length byte */
	size_t dnamebuf_len = sizeof(dnamebuf);
	uint8_t* keytagdname;
	struct module_qstate* newq = NULL;
	enum module_ext_state ext_state = qstate->ext_state[id];

	numtag = anchor_list_keytags(ta, tags, MAX_LABEL_TAGS);
	if(numtag == 0)
		return 0;

	for(i=0; i<numtag; i++) {
		/* Buffer can't overflow; numtag is limited to tags that fit in
		 * the buffer. */
		snprintf(tagstr_pos, tagstr_left, "-%04x", (unsigned)tags[i]);
		tagstr_left -= strlen(tagstr_pos);
		tagstr_pos += strlen(tagstr_pos);
	}

	sldns_str2wire_dname_buf_origin(tagstr, dnamebuf, &dnamebuf_len,
		ta->name, ta->namelen);
	if(!(keytagdname = (uint8_t*)regional_alloc_init(qstate->region,
		dnamebuf, dnamebuf_len))) {
		log_err("could not generate key tag query: out of memory");
		return 0;
	}

	log_nametypeclass(VERB_OPS, "generate keytag query", keytagdname,
		LDNS_RR_TYPE_NULL, ta->dclass);
	if(!generate_request(qstate, id, keytagdname, dnamebuf_len,
		LDNS_RR_TYPE_NULL, ta->dclass, 0, &newq, 1)) {
		verbose(VERB_ALGO, "failed to generate key tag signaling request");
		return 0;
	}

	/* Not interested in subquery response. Restore the ext_state,
	 * that might be changed by generate_request() */
	qstate->ext_state[id] = ext_state;

	return 1;
}
generate_keytag_query(struct module_qstate* qstate, int id,
	struct trust_anchor* ta)
{
	 
#define MAX_LABEL_TAGS (LDNS_MAX_LABELLEN-3)/5
	size_t i, numtag;
	uint16_t tags[MAX_LABEL_TAGS];
	char tagstr[LDNS_MAX_LABELLEN+1] = "_ta";  
	size_t tagstr_left = sizeof(tagstr) - strlen(tagstr);
	char* tagstr_pos = tagstr + strlen(tagstr);
	uint8_t dnamebuf[LDNS_MAX_DOMAINLEN+1];  
	size_t dnamebuf_len = sizeof(dnamebuf);
	uint8_t* keytagdname;
	struct module_qstate* newq = NULL;
	enum module_ext_state ext_state = qstate->ext_state[id];

	numtag = anchor_list_keytags(ta, tags, MAX_LABEL_TAGS);
	if(numtag == 0)
		return 0;

	for(i=0; i<numtag; i++) {
		 
		snprintf(tagstr_pos, tagstr_left, "-%04x", (unsigned)tags[i]);
		tagstr_left -= strlen(tagstr_pos);
		tagstr_pos += strlen(tagstr_pos);
	}

	sldns_str2wire_dname_buf_origin(tagstr, dnamebuf, &dnamebuf_len,
		ta->name, ta->namelen);
	if(!(keytagdname = (uint8_t*)regional_alloc_init(qstate->region,
		dnamebuf, dnamebuf_len))) {
		log_err("could not generate key tag query: out of memory");
		return 0;
	}

	log_nametypeclass(VERB_OPS, "generate keytag query", keytagdname,
		LDNS_RR_TYPE_NULL, ta->dclass);
	if(!generate_request(qstate, id, keytagdname, dnamebuf_len,
		LDNS_RR_TYPE_NULL, ta->dclass, 0, &newq, 1)) {
		verbose(VERB_ALGO, "failed to generate key tag signaling request");
		return 0;
	}

	 
	qstate->ext_state[id] = ext_state;

	return 1;
}