jsommers / pytricia

A library for fast IP address lookup in Python.
GNU Lesser General Public License v3.0
214 stars 22 forks source link

feature request: IPv6 support #6

Closed gescheit closed 8 years ago

gescheit commented 9 years ago

Hello! Seem IPv6 is not supported. I catch segfault in case of IPv6 address.

jsommers commented 9 years ago

Thanks for opening the request. There's some partial support, but it isn't fully supported and I'm not especially surprised about the segfault.

ydhuang28 commented 8 years ago

@gescheit could you provide an example of your code where it segfaulted? It will help in expediting the progress.

wesyoung commented 8 years ago

here's a snip of my py.test code...

ipv6.py

import pytricia
import logging
from pprint import pprint

PERM_WHITELIST = [
    ## TODO -- more
    # http://www.iana.org/assignments/ipv6-multicast-addresses/ipv6-multicast-addresses.xhtml
    # v6
    'FF01:0:0:0:0:0:0:1',
    'FF01:0:0:0:0:0:0:2',
]

class Ipv6(object):

    def __init__(self):
        pass

    # https://github.com/jsommers/pytricia
    def process(self, data, whitelist):
        print('setting up trie')
        wl = pytricia.PyTricia()

        print('adding perm whitelist')
        [wl.insert(x, True) for x in PERM_WHITELIST]

        print('adding submitted whitelist')
        [wl.insert(y, True) for y in whitelist]

        return (y for y in data if y not in wl)

test_ipv6.py

import pytest

from ipv6 import Ipv6
from pprint import pprint

data = [
    '2001:4860:4860::8888'
]

whitelist = [
    '2001:4860:4860::8888',
]

def test_feed_ipv6_whitelist():
    x = Ipv6()

    y = x.process(data, whitelist)

    assert '2001:4860:4860::8888' not in y

understood there's a bunch of ways to describe a v6 address, w/o looking too much at your code, there's not enough room in the buffer.. ?

ydhuang28 commented 8 years ago

I've been running through the code and I think that pytricia.c right now does not have functionality to support IPv6 addresses. Specifically, I think it assumes the addresses given are IPv4.

This issue has been noted and I will work on it.

ydhuang28 commented 8 years ago

@wesyoung yes, that is one problem I think. The buffer assumes that the address is IPv4 (only 32 bytes stack allocated).

The underlying patricia.c code should support IPv6 (it has preprocessing macros that include IPv6 code if the flags are defined).

jsommers commented 8 years ago

v6 support is fixed in the repo. Will update the pypi soon.