Пример #1
0
def daemon(acl, addr='localhost'):
    """ Create an Rbldnsd instance with given ACL
    """
    acl_zone = NamedTemporaryFile()
    acl_zone.writelines("%s\n" % line for line in acl)
    acl_zone.flush()

    dnsd = Rbldnsd(daemon_addr=addr)
    dnsd.add_dataset('acl', acl_zone)
    dnsd.add_dataset('generic', ZoneFile(['test TXT "Success"']))
    return dnsd
Пример #2
0
def _have_ipv6():
    # Check for IPv6 support
    if not getattr(socket, 'has_ipv6', False):
        return False  # no python support for ipv6
    elif Rbldnsd().no_ipv6:
        return False  # rbldnsd compiled with -DNO_IPv6
    try:
        socket.socket(socket.AF_INET6, socket.SOCK_DGRAM).close()
    except socket.error:
        return False  # no kernel (or libc) support for ipv6?
    return True
Пример #3
0
class BTrie(object):
    """ A class to construct and perform lookups on a btrie.

    Since we do not have python bindings for btrie, we do this in a
    roundabout way by running rbldnsd with a single ip6trie dataset,
    and then querying the rbldnsd to perform the lookup.

    """
    def __init__(self, prefixes, **kwargs):
        self.rbldnsd = Rbldnsd(**kwargs)
        zonedata = (self._zone_entry(*prefix) for prefix in prefixes)
        self.rbldnsd.add_dataset('ip6trie', ZoneFile(zonedata))

    def __enter__(self):
        self.rbldnsd.__enter__()
        return self

    def __exit__(self, exc_type, exc_value, exc_tb):
        return self.rbldnsd.__exit__(exc_type, exc_value, exc_tb)

    def lookup(self, prefix, plen):
        prefix = pad_prefix(prefix, plen)
        nibbles = '.'.join("%x" % ((prefix >> n) & 0x0f)
                           for n in range(0, 128, 4))
        return self.rbldnsd.query(nibbles + '.example.com')

    def _zone_entry(self, prefix, plen, data):
        prefix = pad_prefix(prefix, plen)
        ip6addr = ':'.join("%x" % ((prefix >> n) & 0xffff)
                           for n in range(112, -16, -16))
        return "%s/%u :1:%s" % (ip6addr, plen, data)
Пример #4
0
def daemon(acl, addr='localhost'):
    """ Create an Rbldnsd instance with given ACL
    """
    acl_zone = NamedTemporaryFile()
    acl_zone.writelines("%s\n" % line for line in acl)
    acl_zone.flush()

    dnsd = Rbldnsd(daemon_addr=addr)
    dnsd.add_dataset('acl', acl_zone)
    dnsd.add_dataset('generic', ZoneFile(['test TXT "Success"']))
    return dnsd
Пример #5
0
def ip6trie(zone_data):
    """ Run rbldnsd with an ip6trie dataset
    """
    dnsd = Rbldnsd()
    dnsd.add_dataset('ip6trie', ZoneFile(zone_data))
    return dnsd
Пример #6
0
def ip4trie(zone_data):
    """ Run rbldnsd with an ip6trie dataset
    """
    dnsd = Rbldnsd()
    dnsd.add_dataset('ip4trie', ZoneFile(zone_data))
    return dnsd
Пример #7
0
 def __init__(self, prefixes, **kwargs):
     self.rbldnsd = Rbldnsd(**kwargs)
     zonedata = (self._zone_entry(*prefix) for prefix in prefixes)
     self.rbldnsd.add_dataset('ip6trie', ZoneFile(zonedata))