-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewrite_aaaa.py
58 lines (39 loc) · 1.75 KB
/
rewrite_aaaa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# to satisfy Pycharm
# Warning! empty answer will not stored in cache
# from unbound import *
# from unboundmodule import *
def init(id, cfg): return True
def deinit(id): return True
def inform_super(id, qstate, superqstate, qdata): return True
record_types_reject = ['AAAA']
def operate(id, event, qstate, qdata):
if (event == MODULE_EVENT_NEW) or (event == MODULE_EVENT_PASS):
# log_info("pythonmod: module_event_new or module_event_pass")
# pass the query to validator
if (qstate.qinfo.qtype == RR_TYPE_AAAA):
msg = DNSMessage(qstate.qinfo.qname_str, qstate.qinfo.qtype, RR_CLASS_IN, PKT_QR | PKT_RA | PKT_RD)
if not msg.set_return_msg(qstate):
qstate.ext_state[id] = MODULE_ERROR
return True
# TODO: First, we need to get SOA for requested zone,
# beacuse answer without records doesn't stored in cache
# setTTL(qstate, 3600)
# if not storeQueryInCache(qstate, qstate.return_msg.qinfo, qstate.return_msg.rep, 0):
# qstate.ext_state[id] = MODULE_ERROR
# return False
# we don't need validation, result is valid
qstate.return_msg.rep.security = 2
qstate.return_rcode = RCODE_NOERROR
qstate.ext_state[id] = MODULE_FINISHED
return True
# invalidateQueryInCache(qstate, qstate.return_msg.qinfo)
else:
qstate.ext_state[id] = MODULE_WAIT_MODULE
return True
if event == MODULE_EVENT_MODDONE:
log_info("pythonmod: iterator module done")
qstate.ext_state[id] = MODULE_FINISHED
return True
log_err("pythonmod: bad event")
qstate.ext_state[id] = MODULE_ERROR
return True