diff options
author | Rob Austein <sra@hactrn.net> | 2014-06-11 18:22:05 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2014-06-11 18:22:05 +0000 |
commit | d6cfe2a2080e9dfb03aeee7a1aecd359dd393ea9 (patch) | |
tree | df7a24bfc34dff1a5bde71c6e60b9392d15d7b9c | |
parent | 89439c425c95fca242a1f1974441c0e04d65e5fa (diff) |
Handle version mis-match when forcing protocol version. Closes #699.
svn path=/trunk/; revision=5865
-rw-r--r-- | rpki/rtr/client.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/rpki/rtr/client.py b/rpki/rtr/client.py index 7f971846..6d567a1b 100644 --- a/rpki/rtr/client.py +++ b/rpki/rtr/client.py @@ -248,7 +248,7 @@ class ClientChannel(rpki.rtr.channels.PDUChannel): return cls(sock = s[1], proc = subprocess.Popen(argv, stdin = s[0], stdout = s[0], close_fds = True), killsig = signal.SIGINT, - host = host, port = port, version = version) + host = host or "none", port = port or "none", version = version) @classmethod def tls(cls, host, port, version): @@ -271,7 +271,7 @@ class ClientChannel(rpki.rtr.channels.PDUChannel): killsig = signal.SIGKILL, host = host, port = port, version = version) - def setup_sql(self, sqlname): + def setup_sql(self, sqlname, reset_session): """ Set up an SQLite database to contain the table we receive. If necessary, we will create the database. @@ -319,12 +319,16 @@ class ClientChannel(rpki.rtr.channels.PDUChannel): key TEXT NOT NULL, UNIQUE (cache_id, asn, ski), UNIQUE (cache_id, asn, key))''') - + elif reset_session: + cur.execute("DELETE FROM cache WHERE host = ? and port = ?", (self.host, self.port)) cur.execute("SELECT cache_id, version, nonce, serial, refresh, retry, expire, updated " "FROM cache WHERE host = ? AND port = ?", (self.host, self.port)) try: self.cache_id, version, self.nonce, self.serial, refresh, retry, expire, updated = cur.fetchone() + if version is not None and self.version is not None and version != self.version: + cur.execute("DELETE FROM cache WHERE host = ? and port = ?", (self.host, self.port)) + raise TypeError # Simulate lookup failure case if version is not None: self.version = version if refresh is not None: @@ -461,7 +465,7 @@ def client_main(args): try: client = constructor(host = args.host, port = args.port, version = args.force_version) if args.sql_database: - client.setup_sql(args.sql_database) + client.setup_sql(args.sql_database, args.reset_session) polled = client.updated wakeup = None @@ -515,6 +519,7 @@ def argparse_setup(subparsers): subparser.set_defaults(func = client_main, default_log_to = "stderr") subparser.add_argument("--sql-database", help = "filename for sqlite3 database of client state") subparser.add_argument("--force-version", type = int, choices = PDU.version_map, help = "force specific protocol version") + subparser.add_argument("--reset-session", action = "store_true", help = "reset any existing session found in sqlite3 database") subparser.add_argument("protocol", choices = ("loopback", "tcp", "ssh", "tls"), help = "connection protocol") subparser.add_argument("host", nargs = "?", help = "server host") subparser.add_argument("port", nargs = "?", help = "server port") |