|
| 1 | +# Copyright (c) 2011 Robert Mibus & Internode |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person |
| 4 | +# obtaining a copy of this software and associated documentation |
| 5 | +# files (the "Software"), to deal in the Software without |
| 6 | +# restriction, including without limitation the rights to use, |
| 7 | +# copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +# copies of the Software, and to permit persons to whom the |
| 9 | +# Software is furnished to do so, subject to the following |
| 10 | +# conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be |
| 13 | +# included in all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 17 | +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 19 | + |
| 20 | + |
| 21 | +# |
| 22 | +# A pymds source filter. |
| 23 | +# |
| 24 | +# pymdsautogen makes stuff up on the fly |
| 25 | +# |
| 26 | +# initializer: a "base domain" under which AAAA records go, and an IPv6 prefix |
| 27 | +# (for which PTR records work). |
| 28 | +# |
| 29 | + |
| 30 | +import struct |
| 31 | + |
| 32 | +from utils import * |
| 33 | + |
| 34 | +import ipaddr |
| 35 | +import string |
| 36 | +import re |
| 37 | + |
| 38 | +class Source(object): |
| 39 | + def __init__(self, basedomain, v6prefix): |
| 40 | + self._answers = {} |
| 41 | + self.basedomain = basedomain.split('.') |
| 42 | + self.v6prefix = v6prefix |
| 43 | + |
| 44 | + def get_response(self, query, domain, qtype, qclass, src_addr): |
| 45 | + if qtype == 28 or qtype == 255: # 'AAAA' or 'ANY': |
| 46 | + print 'Responding to AAAA query for %s.%s' % (query, domain) |
| 47 | + try: |
| 48 | + # We SHOULD make sure this matches our v6prefix, but currently |
| 49 | + # we don't... |
| 50 | + addr = ipaddr.IPv6Address(query.replace('-',':')) |
| 51 | + return 0, [{ |
| 52 | + 'qtype': 28, # Hard-coded to 'AAAA', in case we're from an ANY query |
| 53 | + 'qclass': qclass, |
| 54 | + 'ttl': 86400, |
| 55 | + 'rdata': addr.packed |
| 56 | + }] |
| 57 | + except: |
| 58 | + print "No AAAA available" |
| 59 | + return 3, [] |
| 60 | + else: # NS, A, MX, etc. -- but don't return NXDOMAIN if there's a PTR or AAAA |
| 61 | + print "Responding to other query type..." |
| 62 | + print "Checking if we have a valid PTR or AAAA record:" |
| 63 | + rcode_aaaa, resp = self.get_response(query, domain, 28, qclass, src_addr) |
| 64 | + if rcode_aaaa == 0: |
| 65 | + print "AAAA found, returning for NS" |
| 66 | + return 0, [] |
| 67 | + else: |
| 68 | + print "No AAAA found, no NS to return..." |
| 69 | + return 3, [] |
0 commit comments