Advertisement
yiorgos

unbound, python and conditional replies

Jul 6th, 2018
691
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def operate(id, event, qstate, qdata):
  2.   if (event == MODULE_EVENT_NEW) or (event == MODULE_EVENT_PASS):
  3.     name = qstate.qinfo.qname_str.rstrip('.')
  4.  
  5.     # Find out source IP address
  6.     rl = qstate.mesh_info.reply_list
  7.     while (rl):
  8.       if rl.query_reply:
  9.         q = rl.query_reply
  10.         break
  11.       rl = rl.next
  12.  
  13.     # Careful with this conditional
  14.     try: addr = q.addr
  15.     except NameError: addr = None
  16.  
  17.     if (addr == "192.168.1.13") and (name == "test.inbox2.eu"):
  18.  
  19.       msg = DNSMessage(qstate.qinfo.qname_str, RR_TYPE_A, RR_CLASS_IN, PKT_QR | PKT_RA | PKT_AA)
  20.       if (qstate.qinfo.qtype == RR_TYPE_A) or (qstate.qinfo.qtype == RR_TYPE_ANY):
  21.         msg.answer.append("%s 10 IN A %s" % (qstate.qinfo.qname_str, "192.168.1.254"))
  22.  
  23.       if not msg.set_return_msg(qstate):
  24.         qstate.ext_state[id] = MODULE_ERROR
  25.         return True
  26.  
  27.       qstate.return_msg.rep.security = 2
  28.       qstate.return_rcode = RCODE_NOERROR
  29.       qstate.ext_state[id] = MODULE_FINISHED
  30.       return True
  31.  
  32.     # not the name we are interested in
  33.     else:
  34.       qstate.ext_state[id] = MODULE_WAIT_MODULE
  35.       return True
  36.  
  37.   if event == MODULE_EVENT_MODDONE:
  38.     qstate.ext_state[id] = MODULE_FINISHED
  39.     return True
  40.  
  41.   qstate.ext_state[id] = MODULE_ERROR
  42.   return True
Advertisement
RAW Paste Data Copied
Advertisement