yiorgos icon

unbound, python and conditional replies

yiorgos | PRO | 07/06/18 03:53:02 PM UTC | 0 ⭐ | 1175 👁️ | Never ⏰ | []
Python |

1.28 KB

|

None

|

0 👍

/

0 👎

def operate(id, event, qstate, qdata):
  if (event == MODULE_EVENT_NEW) or (event == MODULE_EVENT_PASS):
    name = qstate.qinfo.qname_str.rstrip('.')
 
    # Find out source IP address
    rl = qstate.mesh_info.reply_list
    while (rl):
      if rl.query_reply:
        q = rl.query_reply
        break
      rl = rl.next
 
    # Careful with this conditional
    try: addr = q.addr
    except NameError: addr = None
 
    if (addr == "192.168.1.13") and (name == "test.inbox2.eu"):
 
      msg = DNSMessage(qstate.qinfo.qname_str, RR_TYPE_A, RR_CLASS_IN, PKT_QR | PKT_RA | PKT_AA)
      if (qstate.qinfo.qtype == RR_TYPE_A) or (qstate.qinfo.qtype == RR_TYPE_ANY):
        msg.answer.append("%s 10 IN A %s" % (qstate.qinfo.qname_str, "192.168.1.254"))
 
      if not msg.set_return_msg(qstate):
        qstate.ext_state[id] = MODULE_ERROR
        return True
 
      qstate.return_msg.rep.security = 2
      qstate.return_rcode = RCODE_NOERROR
      qstate.ext_state[id] = MODULE_FINISHED
      return True
 
    # not the name we are interested in
    else:
      qstate.ext_state[id] = MODULE_WAIT_MODULE
      return True
 
  if event == MODULE_EVENT_MODDONE:
    qstate.ext_state[id] = MODULE_FINISHED
    return True
 
  qstate.ext_state[id] = MODULE_ERROR
  return True

Comments