def bgpdump_select_main(args): """ * DANGER WILL ROBINSON! * DEBUGGING AND TEST USE ONLY! * Simulate route origin data from a set of BGP dump files. Set current serial number to correspond to an .ax file created by converting BGP dump files. SUCH DATA PROVIDE NO SECURITY AT ALL. * DANGER WILL ROBINSON! * DEBUGGING AND TEST USE ONLY! * """ head, sep, tail = os.path.basename(args.ax_file).partition(".") if not head.isdigit() or sep != "." or not tail.startswith( "ax.v") or not tail[4:].isdigit(): sys.exit("Argument must be name of a .ax file") serial = Timestamp(head) version = int(tail[4:]) if version not in rpki.rtr.pdus.PDU.version_map: sys.exit("Unknown protocol version %d" % version) nonce = rpki.rtr.server.read_current(version)[1] if nonce is None: nonce = rpki.rtr.generator.new_nonce() rpki.rtr.server.write_current(serial, nonce, version) rpki.rtr.generator.kick_all(serial)
def __init__(self): self.timestamps = [ Timestamp(int(f.split(".")[0])) for f in glob.iglob("*.ax.v*") ] self.timestamps.sort() self.offset = self.timestamps[0] - int(time.time()) self.nonce = rpki.rtr.generator.new_nonce()
def from_bgpdump(line, rib_dump): try: assert isinstance(rib_dump, bool) fields = line.split("|") # Parse prefix, including figuring out IP protocol version cls = rpki.rtr.generator.IPv6PrefixPDU if ":" in fields[ 5] else rpki.rtr.generator.IPv4PrefixPDU self = cls() self.timestamp = Timestamp(fields[1]) p, l = fields[5].split("/") self.prefix = rpki.POW.IPAddress(p) self.prefixlen = self.max_prefixlen = int(l) # Withdrawals don't have AS paths, so be careful assert fields[2] == "B" if rib_dump else fields[2] in ("A", "W") if fields[2] == "W": self.asn = 0 self.announce = 0 else: self.announce = 1 if not fields[6] or "{" in fields[6] or "(" in fields[6]: raise IgnoreThisRecord a = fields[6].split()[-1] if "." in a: a = [int(s) for s in a.split(".")] if len(a) != 2 or a[0] < 0 or a[0] > 65535 or a[ 1] < 0 or a[1] > 65535: logging.warn("Bad dotted ASNum %r, ignoring record", fields[6]) raise IgnoreThisRecord a = (a[0] << 16) | a[1] else: a = int(a) self.asn = a self.check() return self except IgnoreThisRecord: raise except Exception, e: logging.warn("Ignoring line %r: %s", line, e) raise IgnoreThisRecord
os.chdir(args.rpki_rtr_dir) except OSError, e: logging.critical(str(e)) sys.exit(1) for version in sorted(rpki.rtr.server.PDU.version_map.iterkeys(), reverse=True): logging.debug("# Generating updates for protocol version %d", version) old_ixfrs = glob.glob("*.ix.*.v%d" % version) current = rpki.rtr.server.read_current(version)[0] cutoff = Timestamp.now(-(24 * 60 * 60)) for f in glob.iglob("*.ax.v%d" % version): t = Timestamp(int(f.split(".")[0])) if t < cutoff and t != current: logging.debug("# Deleting old file %s, timestamp %s", f, t) os.unlink(f) pdus = rpki.rtr.generator.AXFRSet.parse_rcynic(args.rcynic_dir, version, args.scan_roas, args.scan_routercerts) if pdus == rpki.rtr.generator.AXFRSet.load_current(version): logging.debug("# No change, new serial not needed") continue pdus.save_axfr() for axfr in glob.iglob("*.ax.v%d" % version): if axfr != pdus.filename(): pdus.save_ixfr(rpki.rtr.generator.AXFRSet.load(axfr)) pdus.mark_current(args.force_zero_nonce)