Bug 4200

Summary: More documentation needed on Pythonmod inplace_callback functions
Product: unbound Reporter: Michael <support>
Component: serverAssignee: unbound team <unbound-team>
Status: NEW ---    
Severity: enhancement CC: cathya, support
Priority: P5    
Version: 1.8.1   
Hardware: x86_64   
OS: FreeBSD   

Description Michael 2018-10-30 09:35:44 CET
As I mentioned previously on https://www.nlnetlabs.nl/bugs-script/show_bug.cgi?id=4140 we need to change answer on specific rules.
I figured out, that after first reply, the answer is cached, and the only way to catch it - inplace callback functions. I am happy with new comm_reply parameter in callback functions, but still I can't figure out how to change RRSets in answer message. I can't read them even through reply_info* rep struct. Looks like i should pack somehow answer and pass it through regional* region struct, but there are no methods or functions for that.
Could you point me to some documentation/source code or example on how to change reply message(totally replace) while in inplace_*_callback?
I've tried the following approach:
def inplace_cache_callback(qinfo, qstate, rep, rcode, edns, opt_list_out, region, **kwargs):
	comm_reply = kwargs['repinfo']
	if comm_reply:
		addr = comm_reply.addr
		port = comm_reply.port
		addr_family = comm_reply.family
		if "" in addr:
		rl = qstate.mesh_info.reply_list
		while (rl):
			if rl.query_reply:
				q = rl.query_reply
				counter +=1
				if "" in q.addr:
			rl = rl.next
		log_info("python: total count {}".format(counter))
	return True

def makeReply(qstate):
	msg = DNSMessage(qstate.qinfo.qname_str, RR_TYPE_A, RR_CLASS_IN, PKT_QR | PKT_RA | PKT_AA)
	#append RR
	if (qstate.qinfo.qtype == RR_TYPE_A) or (qstate.qinfo.qtype == RR_TYPE_ANY):
		log_info("message generated and modified")
		msg.answer.append("%s 0 IN A" % qstate.qinfo.qname_str)
	#set qstate.return_msg
	if not msg.set_return_msg(qstate):
		return True

This code doesn't work for me, should it?