Project

General

Profile

Feature #9251 ยป netflix-no-aaaa.py

Jim Pingle, 01/08/2020 11:16 AM

 
1
def init(id, cfg):
2
    return True
3

    
4
def deinit(id):
5
    return True
6

    
7
def inform_super(id, qstate, superqstate, qdata):
8
    return True
9

    
10
domains = [
11
    "netflix.com.",
12
    "nflxso.net.",
13
]
14

    
15
def operate(id, event, qstate, qdata):
16
    if event == MODULE_EVENT_NEW or event == MODULE_EVENT_PASS:
17
        if qstate.qinfo.qtype != RR_TYPE_AAAA:
18
            qstate.ext_state[id] = MODULE_WAIT_MODULE
19
            return True
20

    
21
        for domain in domains:
22
            if qstate.qinfo.qname_str == domain or qstate.qinfo.qname_str.endswith("." + domain):
23
                msg = DNSMessage(qstate.qinfo.qname_str, RR_TYPE_A, RR_CLASS_IN, PKT_QR | PKT_RA | PKT_AA)
24
                if not msg.set_return_msg(qstate):
25
                    qstate.ext_state[id] = MODULE_ERROR
26
                    return True
27
                # We don't need validation, result is valid
28
                qstate.return_msg.rep.security = 2
29
                qstate.return_rcode = RCODE_NOERROR
30
                qstate.ext_state[id] = MODULE_FINISHED
31
                log_info("no-aaaa: blocking AAAA request for %s" % qstate.qinfo.qname_str)
32
                return True
33

    
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
43

    
44
log_info("pythonmod: script loaded")
45

    
    (1-1/1)