aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rpkid/rpki/ipaddrs.py31
-rwxr-xr-xrtr-origin/updater.py11
2 files changed, 36 insertions, 6 deletions
diff --git a/rpkid/rpki/ipaddrs.py b/rpkid/rpki/ipaddrs.py
index 32be2cb0..1bcb425e 100644
--- a/rpkid/rpki/ipaddrs.py
+++ b/rpkid/rpki/ipaddrs.py
@@ -12,7 +12,23 @@ once, here, thus avoiding a lot of duplicate code elsewhere.
$Id$
-Copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
+
+Copyright (C) 2009 Internet Systems Consortium ("ISC")
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+
+Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN")
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -45,9 +61,13 @@ class v4addr(long):
x = y[0]
return long.__new__(cls, x)
+ def to_bytes(self):
+ """Convert a v4addr object to a raw byte string."""
+ return struct.pack("!I", long(self))
+
def __str__(self):
"""Convert a v4addr object to string format."""
- return socket.inet_ntop(socket.AF_INET, struct.pack("!I", long(self)))
+ return socket.inet_ntop(socket.AF_INET, self.to_bytes())
class v6addr(long):
"""IPv6 address.
@@ -64,7 +84,10 @@ class v6addr(long):
x = (y[0] << 64) | y[1]
return long.__new__(cls, x)
+ def to_bytes(self):
+ """Convert a v6addr object to a raw byte string."""
+ return struct.pack("!QQ", long(self) >> 64, long(self) & 0xFFFFFFFFFFFFFFFF)
+
def __str__(self):
"""Convert a v6addr object to string format."""
- return socket.inet_ntop(socket.AF_INET6,
- struct.pack("!QQ", long(self) >> 64, long(self) & 0xFFFFFFFFFFFFFFFF))
+ return socket.inet_ntop(socket.AF_INET6, self.to_bytes())
diff --git a/rtr-origin/updater.py b/rtr-origin/updater.py
index d97e5e42..58d14daa 100755
--- a/rtr-origin/updater.py
+++ b/rtr-origin/updater.py
@@ -23,7 +23,7 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
"""
-import sys, os, rpki.x509, rpki.ipaddrs
+import sys, os, struct, rpki.x509, rpki.ipaddrs
rcynic_dir = "../rcynic/rcynic-data/authenticated"
@@ -54,11 +54,18 @@ class prefix(object):
if c > 0: c = 1
return c
+ def to_pdu(self, announce = 1, color = 0):
+ return (struct.pack("!BBHBBBB", 0, self.pdu_type, color, announce, self.prefixlen, self.max_prefixlen, 0) +
+ self.prefix.to_bytes() +
+ struct.pack("!L", self.asn))
+
class v4prefix(prefix):
addr_type = rpki.ipaddrs.v4addr
+ pdu_type = 4
class v6prefix(prefix):
addr_type = rpki.ipaddrs.v6addr
+ pdu_type = 6
prefix.map = { "\x00\x01" : v4prefix,
"\x00\x02" : v6prefix }
@@ -82,4 +89,4 @@ for i in xrange(len(prefixes) - 2, -1, -1):
del prefixes[i + 1]
for p in prefixes:
- print p
+ print "%-40s %s" % (p, ":".join(("%02X" % ord(i) for i in p.to_pdu())))