From 75fe7f88b8e048d8793ec73540d3ee29d1232a4b Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 21 Sep 2021 00:18:30 +0100 Subject: [PATCH] server/admin.c: Add `-quiet' options to `forcekx' and `kill'. These will be useful in testing. Document them anyway, even though they're probably useless for any other purpose. --- py/tripe.py.in | 12 ++++++++---- server/admin.c | 27 +++++++++++++++++++++++---- server/tripe-admin.5.in | 31 ++++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/py/tripe.py.in b/py/tripe.py.in index db194e29..e9eb0d3c 100644 --- a/py/tripe.py.in +++ b/py/tripe.py.in @@ -859,8 +859,10 @@ class TripeCommandDispatcher (TripeConnection): *['EPING'] + _kwopts(kw, ['timeout']) + [peer])) - def forcekx(me, peer): - return _simple(me.command('FORCEKX', peer)) + def forcekx(me, peer, **kw): + return _simple(me.command(*['FORCEKX'] + + _kwopts(kw, ["quiet"]) + + [peer])) def getchal(me): return _oneline(me.command('GETCHAL', filter = _tokenjoin)) def greet(me, peer, chal): @@ -869,8 +871,10 @@ class TripeCommandDispatcher (TripeConnection): return list(me.command('HELP', filter = _tokenjoin)) def ifname(me, peer): return _oneline(me.command('IFNAME', peer, filter = _tokenjoin)) - def kill(me, peer): - return _simple(me.command('KILL', peer)) + def kill(me, peer, **kw): + return _simple(me.command(*['KILL'] + + _kwopts(kw, ["quiet"]) + + [peer])) def list(me): return list(me.command('LIST', filter = _tokenjoin)) def notify(me, *msg): diff --git a/server/admin.c b/server/admin.c index 221b249e..4bab4404 100644 --- a/server/admin.c +++ b/server/admin.c @@ -2101,21 +2101,40 @@ static void acmd_stats(admin *a, unsigned ac, char *av[]) static void acmd_kill(admin *a, unsigned ac, char *av[]) { peer *p; + int bye = 1; + OPTIONS(ac, av, { + OPT("-quiet", { bye = 0; }) + }); + if (!*av || av[1]) goto bad_syntax; if ((p = a_findpeer(a, av[0])) != 0) { - p_destroy(p, 1); + p_destroy(p, bye); a_ok(a); } + return; + +bad_syntax: + a_fail(a, "bad-syntax", "kill", "[OPTIONS] PEER", A_END); } static void acmd_forcekx(admin *a, unsigned ac, char *av[]) { peer *p; + int quiet = 0; + OPTIONS(ac, av, { + OPT("-quiet", { quiet = 1; }) + }); + if (!*av || av[1]) goto bad_syntax; if ((p = a_findpeer(a, av[0])) != 0) { - kx_start(&p->kx, 1); + if (!quiet) kx_start(&p->kx, 1); + else { p->kx.t_valid = time(0) - T_VALID - 1; } a_ok(a); } + return; + +bad_syntax: + a_fail(a, "bad-syntax", "forcekx", "[OPTIONS] PEER", A_END); } static void acmd_reload(admin *a, unsigned ac, char *av[]) @@ -2159,13 +2178,13 @@ static const acmd acmdtab[] = { { "checkchal", "CHAL", 1, 1, acmd_checkchal }, { "daemon", 0, 0, 0, acmd_daemon }, { "eping", "[OPTIONS] PEER", 1, 0xffff, acmd_eping }, - { "forcekx", "PEER", 1, 1, acmd_forcekx }, + { "forcekx", "[OPTIONS] PEER", 1, 0xffff, acmd_forcekx }, { "getchal", 0, 0, 0, acmd_getchal }, { "greet", "PEER CHAL", 2, 2, acmd_greet }, { "help", 0, 0, 0, acmd_help }, { "ifname", "PEER", 1, 1, acmd_ifname }, { "jobs", 0, 0, 0, acmd_jobs }, - { "kill", "PEER", 1, 1, acmd_kill }, + { "kill", "[OPTIONS] PEER", 1, 0xffff, acmd_kill }, { "list", 0, 0, 0, acmd_list }, { "notify", "MESSAGE ...", 1, 0xffff, acmd_notify }, { "peerinfo", "PEER", 1, 1, acmd_peerinfo }, diff --git a/server/tripe-admin.5.in b/server/tripe-admin.5.in index e637650a..3e7bd8ef 100644 --- a/server/tripe-admin.5.in +++ b/server/tripe-admin.5.in @@ -571,10 +571,24 @@ responses are the same as for the .B PING command. .SP -.BI "FORCEKX " peer +.BI "FORCEKX \fR[" options "\fR] " peer Requests the server to begin a new key exchange with .I peer -immediately. +immediately. The following options are recognized. +.RS +.\"+opts +.TP +.B "\-quiet" +Don't actually start a new key exchange; just quietly mark any previous +key exchange as stale so that a fresh attempt from the peer will +succeed. This is was introduced for use during testing, but it's also +useful when a remote peer has forgotten about us: it would be +annoying if, once it's learns about us and tries to reinitiate a key +exchange, we ignore it because we think we've already done one recently; +on the other hand, forcing a key exchange before the remote peer has +been reinformed about us is a waste of packets. +.\"-opts +.RE .SP .B "GETCHAL" Requests a challenge. The challenge is returned in an @@ -620,7 +634,18 @@ message is sent to the peer if it's marked as .B "\-ephemeral" \(en see the .B "ADD" -command. +command. The following options are +recognized. +.RS +.\"+opts +.TP +.B "\-quiet" +Suppress any +.B bye +message to an ephemeral peer: just quietly forget about it. This is +used during testing, and is not expected to be generally useful. +.\"-opts +.RE .SP .B "LIST" For each currently-known peer, an -- 2.11.0