[mirrorbrain] [PATCH] IPv6 support for mod_asn - Apparently a very low hanging fruit.

From: Christian Rohmann <crohmann_at_netcologne.de>
Date: Sat, 14 Jun 2014 02:49:04 +0200 (CEST)
Hey all,

first let me say that mirrorbrain is serving the world well, thanks for a good
piece of software! We receive most requests to our open-source mirror
(mirror.netcologne.de) through mirrorbrain redirectors and also our Sourceforge
mirror seems to be sending us the right people for downloads most of the time.

With the adoption of IPv6 for more and more end user connections I believe it's
necessary that mod_asn is also able to match IPv6 addresses to their AS and get
the users to the closest IPv6-enabled mirror possible. While mirrorbrain itself
is quite capable IPv6-wise and even does IPv6 geo-ip, mod_asn lacks a bit in
looking up the AS for IPv6 addresses.

So I took a look at the PostgreSQL extention data type "ip4r" you are already
using to do the prefix lookups. Back in the days it was not supporting IPv6
well, as you stated on http://mirrorbrain.org/mod_asn/development-status/.
But as I found out this has changed dramatically towards the now current 2.0.2.
Not only does ip4r support IPv6, you can even put IPv4 and IPv6 prefixes
together in one column using the type iprange (they describe it with "an
arbitrary range of IPv4 or IPv6 addresses").

So I changed the  pfx2asn table to use this type instead of just "ip4r" via:
 ALTER TABLE pfx2asn ALTER pfx TYPE iprange;

I put in a few prefixes to test ...

 INSERT INTO pfx2asn VALUES('2001:4dd0::/32', 8422);
 INSERT INTO pfx2asn VALUES('2001:4dd0::/29', 8422);
 INSERT INTO pfx2asn VALUES('2001:4dd1::/32', 8422);
 INSERT INTO pfx2asn VALUES('2001:4dd2::/32', 8422);
 INSERT INTO pfx2asn VALUES('2001:4dd3::/32', 8422);

I then played with it a bit querying the table for the AS for a given IPv6
prefix. I changed the query just a bit to make it flexible in taking IPv4 as
well as IPv6 addresses for the matching and uses the "_at_" operator to do the
ordering:

mirrorbrain=# SELECT pfx, asn FROM pfx2asn WHERE pfx >>=
ipaddress('2001:4dd0::1') ORDER BY _at_ pfx;
      pfx       | asn
----------------+------
 2001:4dd0::/32 | 8422
 2001:4dd0::/29 | 8422
(2 rows)

mirrorbrain=# SELECT pfx, asn FROM pfx2asn WHERE pfx >>=
ipaddress('2001:4dd1::1') ORDER BY _at_ pfx;
      pfx       | asn
----------------+------
 2001:4dd1::/32 | 8422
 2001:4dd0::/29 | 8422
(2 rows)

mirrorbrain=# SELECT pfx, asn FROM pfx2asn WHERE pfx >>=
ipaddress('194.8.197.22') ORDER BY _at_ pfx;
      pfx       | asn
----------------+------
 194.8.192.0/19 | 8422
(1 row)

as you can see it works just as it should, giving back the correct order, IPv4
and IPv6 prefixes in harmony !

As for the operator "_at_" vs "@@" I am not yet sure if it really makes a
difference in practice. The documentation of ip4r says:
  _at_ a               | approximate size of a (returns double)
  _at_@ a            | exact size of a (returns numeric)


Given the ability to now also look up AS numbers for IPv6 addresses with a
single query, mod_asn itself needs very little code change. I put in a new
default query, and of course did remove the IPv6 check that avoided even looking
up IPv6 addresses in the first place.
Attached you find a patch against the current 1.6 of mod_asn.c which does
exactly those changes and also a changed asn.sql file which uses the iprange
data type.


With those changes mod_asn now returns X-Prefix and X-AS headers for IPv6
prefixes ...

 # curl --head
http://[2001:4dd3:1234:1234:1234:1234:1234:1234]/download/testfile.txt
 HTTP/1.1 200 OK
 Date: Sat, 14 Jun 2014 00:10:24 GMT
 Server: Apache/2.4.9 (Debian)
 X-Prefix: 2001:4dd3::/32
 X-AS: 8422




The only piece to the IPv6 puzzle that is missing to me at least, is a good
source for the IPv6 prefixes <-> AS list in plain just like there is with
http://www.routeviews.org/ for IPv4. If someone has BGP full-table running on
maybe a looking glass router one can simply get it from there, but that is of
course not something for everyone. So this needs some thought and then the
appropriate addition to the provided script to gather the data and put it into
the database.



So what are your thoughts on this?
Did I miss anything here?



Regards

Christian


_______________________________________________
mirrorbrain mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain/

Note: To remove yourself from this mailing list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-request_at_mirrorbrain.org


Received on Sat Jun 14 2014 - 12:20:31 GMT

This archive was generated by hypermail 2.3.0 : Sat May 09 2015 - 01:47:05 GMT