chiark / gitweb /
svc/connect.in: Add a new `sabotage' command to test ping-failure actions.
[tripe] / svc / connect.8.in
CommitLineData
a62f8e8a
MW
1.\" -*-nroff-*-
2.\".
3.\" Manual for the connect service
4.\"
5.\" (c) 2008 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of Trivial IP Encryption (TrIPE).
11.\"
11ad66c2
MW
12.\" TrIPE is free software: you can redistribute it and/or modify it under
13.\" the terms of the GNU General Public License as published by the Free
14.\" Software Foundation; either version 3 of the License, or (at your
15.\" option) any later version.
a62f8e8a 16.\"
11ad66c2
MW
17.\" TrIPE is distributed in the hope that it will be useful, but WITHOUT
18.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.\" for more details.
a62f8e8a
MW
21.\"
22.\" You should have received a copy of the GNU General Public License
11ad66c2 23.\" along with TrIPE. If not, see <https://www.gnu.org/licenses/>.
a62f8e8a
MW
24.
25.\"--------------------------------------------------------------------------
26.so ../defs.man.in \"@@@PRE@@@
27.
28.\"--------------------------------------------------------------------------
0647ba7c 29.TH connect 8tripe "11 December 2007" "Straylight/Edgeware" "TrIPE: Trivial IP Encryption"
a62f8e8a
MW
30.
31.\"--------------------------------------------------------------------------
32.SH "NAME"
33.
d64ce4ae 34connect \- tripe service to handle addition and removal of peers
a62f8e8a
MW
35.
36.\"--------------------------------------------------------------------------
37.SH "SYNOPSIS"
38.
39.B connect
40.RB [ \-a
41.IR socket ]
42.RB [ \-d
43.IR dir ]
44.RB [ \-p
45.IR file ]
46.br
47\& \c
48.RB [ \-\-daemon ]
49.RB [ \-\-debug ]
50.RB [ \-\-startup ]
51.
52.\"--------------------------------------------------------------------------
53.SH "DESCRIPTION"
54.
55The
56.B connect
d64ce4ae
MW
57service tracks associations with peers and performs various actions at
58appropriate stages in the assocations' lifecycles. It also registers
59new peers with the
a62f8e8a 60.BR tripe (8)
d64ce4ae
MW
61server on demand.
62.PP
63For example:
64.hP \*o
65When a peer is added, it arranges to configure the corresponding network
66interface correctly, and (if necessary) to initiate a dynamic
67connection.
68.hP \*o
69When a peer is removed, it arranges to bring down the network interface.
70.hP \*o
71While the peer is known, it
72.BR PING s
73it at regular intervals. If the peer fails to respond, it can be
74removed or reconnected.
a62f8e8a
MW
75.PP
76A peer may participate
77.I actively
78or
79.I passively
80in a connection. A peer participating actively (an
81.IR "active peer" )
82must already know its peer's connection details \(en its server's IP
83address and port. Active connection is suitable when the peer is a
84well-known server with stable details.
85.PP
86A server participating passively (a
87.IR "passive peer" )
88waits to be contacted by its peer, and discovers the peer's IP address
89and port as a result of a simple protocol described below. Passive
90connection is suitable when the peer's IP address or port can vary over
91time \(en e.g., if its IP address is assigned dynamically by DHCP or
92PPP, or if it is hidden behind a NAT firewall.
93.PP
94If both peers are active, we say that they establish an
95.IR "static connection" ;
96if one is passive, we say that they establish a
97.IR "dynamic connection" .
98At least one of the peers must be active; it is not possible to
99establish a connection if both peers are passive.
100.SS "Command line"
101In addition to the standard options described in
102.BR tripe-service (7),
103the following command-line options are recognized.
104.TP
105.BI "\-p, \-\-peerdb=" file
106Use
107.I file
108as the (CDB format) peer database. In the absence of this option, the
109file named by the
110.B TRIPEPEERDB
111environment variable is used; if that's not set either, then the default
112default of
113.B peers.cdb
114in the current working directory is used instead.
d64ce4ae
MW
115.
116.\"--------------------------------------------------------------------------
117.SH "BEHAVIOUR"
118.
119.SS "Adoption"
120The
121.B connect
122service maintains a list of peers which it has adopted. A peer is
123.I eligible for adoption
124if it has a record in the peer database
125.BR peers.cdb (5)
126in which the
127.B watch
128key is assigned the value
129.BR t ,
130.BR true ,
131.BR y ,
132.BR yes ,
133or
134.BR on .
135.PP
136The service pings adopted peers periodically in order to ensure that
137they are alive, and takes appropriate action if no replies are received.
a62f8e8a 138.PP
d64ce4ae
MW
139A peer is said to be
140.I adopted
141when it is added to this list, and
142.I disowned
143when it removed.
144.
145.SS "Configuring interfaces"
146The
147.B connect
148service configures network interfaces by invoking an
149.B ifup
150script. The script is invoked as
151.IP
152.I script
153.IR args ...
154.I peer
155.I ifname
156.IR addr ...
157.PP
158where the elements are as described below.
159.TP
160.IR script " and " args
161The peer's database record is retrieved; the value assigned to the
162.B ifup
163key is split into words (quoting is allowed; see
164.BR tripe-admin (5)
165for details). The first word is the
166.IR script ;
167subsequent words are gathered to form the
168.IR args .
169.TP
170.I peer
171The name of the peer.
172.TP
173.I ifname
174The name of the network interface associated with the peer, as returned
175by the
176.B IFNAME
177administration command (see
178.BR tripe-admin (5)).
179.TP
180.I addr
181The network address of the peer's TrIPE server, in the form output by
182the
183.B ADDR
184administration command (see
185.BR tripe-admin (5)).
186The first word of
187.I addr
188is therefore a network address family, e.g.,
189.BR INET .
190.PP
191The
192.B connect
193service deconfigures interfaces by invoking an
194.B ifdown
195script, in a similar manner. The script is invoked as
196.IP
197.I script
198.IR args ...
199.I peer
200.PP
201where the elements are as above, except that
202.I script
203and
204.I args
205are formed by splitting the value associated with the peer record's
206.B ifdown
207key.
208.PP
209In both of the above cases, if the relevant key (either
210.B ifup
211or
212.BR ifdown )
213is absent, no action is taken.
214.PP
215The key/value pairs in the peer's database record and the server's
216response to the
217.B ALGS
218administration command (see
219.BR tripe-admin (5))
220are passed to the
221.B ifup
222and
223.B ifdown
224scripts as environment variables. The environment variable name
225corresponding to a key is determined as follows:
226.hP \*o
227Convert all letters to upper-case.
228.hP \*o Convert all sequences of one or more non-alphanumeric characters
229to an underscore
230.RB ` _ '.
231.hP \*o Prefix the resulting name by
232.RB ` P_ '
233or
234.RB ` A_ '
235depending on whether it came from the peer's database record or the
236.B ALGS
237output respectively.
238.PP
239For example,
240.B ifname
241becomes
242.BR P_IFNAME ;
243and
244.B cipher-blksz
245becomes
246.BR A_CIPHER_BLKSZ .
247.
248.SS "Dynamic connection"
249If a peer's database record assigns a value to the
250.B connect
251key, then the
252.B connect
253service will attempt to establish a connection dynamically with the
254peer. The value of the
255.B connect
256key is invoked as a Bourne shell command, i.e.,
257.IP
258.B /bin/sh \-c
259.I connect
260.PP
261is executed. The command is expected to contact the remote server and
262report, on standard output, a challenge string, typically by issuing
263a
264.B passive
265command to the instance of the
266.B connect
267service running on the peer. The
268.B connect
269service reads this challenge, and submits the command
270.IP
271.B GREET
272.I peer
273.I challenge
274.PP
275Typically, the
276.B connect
277command will issue a command such as
278.IP
279.B SVCSUBMIT connect passive
280.I our-name
281.PP
282where
283.I our-name
284is the remote peer's name for this host.
285.PP
286Similarly, if the database record has a
287.B disconnect
288entry, then
289.B connect
290will use this to give the peer explicit notification that its services
291are no longer needed. The value of the
292.B disconnect
293key is invoked as a Bourne shell command. This ought to result in a
294.B KILL
295command being issued to the peer's server.
296.PP
297In detail, the protocol for passive connection works as follows.
a62f8e8a
MW
298.hP 1.
299The active peer
300.BR ADD s
301its partner, typically using the
302.B \-cork
303option to suppress the key-exchange message which the server usually
304sends immediately, since otherwise the passive peer will warn about it.
305.hP 2.
d64ce4ae 306The active peer issues the command
a62f8e8a
MW
307.RS
308.IP
309.B SVCSUBMIT connect passive
310.I user
311.PP
312to the passive peer's server. (Here,
313.I user
d64ce4ae
MW
314is a name identifying the active peer; see below.) Doing this is the
315responsibility of the
316.B connect
317command.
a62f8e8a
MW
318.RE
319.hP 3.
320The
321.B connect
322service on the passive peer responds with a
323.I challenge
324\(en a short Base64-encoded string. Somehow this challenge is sent back
325to the passive peer without being intercepted.
326.hP 4.
327The active peer sends a
328.BR GREET ing
329containing the challenge to its passive partner. The passive server
330announces the arrival of this message, and the originating address and
331port.
332.hP 5.
333The
334.B connect
335service running on the passive host receives the notification, matches
336it up with the
337.I user
338from the initial connection request, and
339.BR ADD s
340the appropriate peer, with the address from the
341.BR GREET ing.
d64ce4ae
MW
342.
343.SS "Operation"
344On startup,
345.B connect
346requests a list of current peers from the
347.BR tripe (8)
348server, and adopts any eligible peers. If the
349.B \-\-startup
350flag was passed on the command line, the newly adopted peers have their
351interfaces configured and connection attempts are made.
a62f8e8a 352.PP
d64ce4ae
MW
353Adopted peers are pinged at regular intervals (using the
354.B PING
355administrative command; see
356.BR tripe-admin (5)).
357This process can be configured by assigning values to keys in the peer's
358database record. Some of these parameters are time intervals,
359expressed as a nonnegative integer followed optionally by
360.BR d ,
361.BR h ,
362.BR m ,
363or
364.B s
365for days, hours, minutes, or seconds, respectively; if no suffix is
366given, seconds are assumed.
367.PP
368The parameters are as follows.
369.TP
370.B every
371A time interval: how often to ping the peer to ensure that it's still
02c99524
MW
372alive. The default is 30 seconds for active dynamic peers, and 5
373minutes for passive peers.
374.IP
375The period for dynamic peers should be no longer than
376.I timeout
377\(mu
378.RI ( retries
379\- 1). Consider an idle mobile peer which has its IP address changed
380just before its passive peer begins pinging. The static peer's pings
381will go to the old address until it receives a ping back from the mobile
382peer. Therefore, the static peer has to keep pinging until it would
383definitely have received an unsolicited ping from the mobile peer, and
384therefore be informed of the change of address. And it's no use
385learning about the change of address just after sending the last ping to
386the old address, so the last retry doesn't count for the purposes of
387this calculation.
388.IP
389Besides, the consequences of failed pinging differ between dynamic and
390passive peers. In the former case, a failure provokes a reconnection
391attempt, after which (hopefully) things will work again: it's probably a
392good thing to check frequently and fail fast. In the latter case, the
393dynamic peer will certainly have to notice that it's been abandoned and
394arrange to retry, causing a communication failure where maybe there
395wasn't really one before.
d64ce4ae
MW
396.TP
397.B timeout
398A time interval: how long to wait for a reply before retrying or giving
399up. The default is 10 seconds.
400.TP
401.B retries
402An integer: how many failed attempts to make before deciding that the
403peer is unreachable and taking action. The default is 5 attempts.
404.PP
405The algorithm is as follows. Send up to
406.I retries
407pings; if a reply is received before the
408.I timeout
409then the peer is alive; wait
410.I every
411and check again. If no reply is received within the
412.IR timeout ,
413then try again up to
414.I retries
415times. If no attempt succeeds, the peer is declared unreachable. If
416the peer has a
417.B connect
418command (i.e., it connects dynamically) then another connection attempt
419is made. Otherwise the peer is killed.
a62f8e8a
MW
420.
421.\"--------------------------------------------------------------------------
422.SH "SERVICE COMMAND REFERENCE"
423.
424.\"* 10 Service commands
425The commands provided by the service are as follows.
426.SP
427.BI "active " peer
428Make an active connection to the named
429.IR peer .
430The service will submit the command
431.RS
432.IP
433.B ADD
434.RB [ \-cork ]
435.RB [ \-keepalive
436.IR time ]
48b84569
MW
437.RB [ \-key
438.IR tag ]
d64ce4ae
MW
439.RB [ \-priv
440.IR tag ]
6411163d 441.RB [ \-mobile ]
a62f8e8a
MW
442.RB [ \-tunnel
443.IR driver ]
444.I address
445.PP
446Specifically:
447.hP \*o
448The option
449.B \-cork
450is provided if the peer's database record assigns the
451.B cork
452key one of the values
453.BR t ,
454.BR true ,
455.BR y ,
456.BR yes,
457or
458.BR on .
459.hP \*o
460The option
461.B \-keepalive
462.I time
463is provided if the database record assigns a value
464.I time
465to the
466.B keepalive
467key.
468.hP \*o
469The option
48b84569
MW
470.B \-key
471.I tag
472is provided if the database record assigns a value
473.I tag
474to the
475.B key
476key.
477.hP \*o
478The option
d64ce4ae
MW
479.B \-priv
480.I tag
481is provided if the database record assigns a value
482.I tag
483to the
484.B priv
485key.
486.hP \*o
487The option
6411163d
MW
488.B \-mobile
489is provided if the peer's database record assigns the
490.B mobile
491key one of the values
492.BR t ,
493.BR true ,
494.BR y ,
495.BR yes,
496or
497.BR on .
498.hP \*o
499The option
a62f8e8a
MW
500.B \-tunnel
501.I driver
502is provided if the database record assigns a value
503.I driver
504to the
505.B tunnel
506key.
507.hP \*o
508The
509.I address
510is the value assigned to the
511.B peer
512key in the database record.
513.RE
514.SP
d64ce4ae
MW
515.B adopted
516For each peer being tracked by the
517.B connect
518service, write a line
519.B INFO
520.IR name .
521(Compatibility note: it's possible that further information will be
522provided about each peer, in the form of subsequent tokens. Clients
523should be prepared to ignore such tokens.)
524.SP
a62f8e8a 525.BI "info " peer
b9dedfa6 526Lists the database record and additional information about the named
a62f8e8a
MW
527.IR peer .
528For each key/value pair, a line
529.RS
530.IP
531.B INFO
532.IB key = value
533.PP
534is output. The key/value pairs are output in an arbitrary order.
b9dedfa6
MW
535.PP
536In addition to the fields of the peer's database record, the following
537additional keys are defined.
538.TP
539.B failures
540The number of failed pings in the current or most recent batch, in
541decimal.
542.TP
543.B last-ping
544The round-trip time of the most recent ping in milliseconds, in the form
545.IB nn.n ms\fR,
546or
547.B timeout
548if the most recent ping timed out,
549or
550.B \-
551if no pings have yet completed.
552.TP
553.B max-ping
554The maximum successful ping time so far in milliseconds, in the form
555.IB nn.n ms\fR,
556or
557.B \-
558if no pings have yet succeeded.
559.TP
560.B mean-ping
561The average successful ping time so far in milliseconds, in the form
562.IB nn.n ms\fR,
563or
564.B \-
565if no pings have yet succeeded.
566.TP
567.B min-ping
568The minimum successful ping time so far in milliseconds, in the form
569.IB nn.n ms\fR,
570or
571.B \-
572if no pings have yet succeeded.
573.TP
574.B n-lost
575The number of pings which have been declared timed out so far, in
576decimal.
577.TP
578.B n-ping
579The number of successful pings so far, in decimal.
580.TP
581.B sd-ping
582The standard deviation of ping times so far in milliseconds, in the form
583.IB nn.n ms\fR,
584or
585.B \-
586if no pings have yet succeeded.
587.TP
588.B state
589One of the strings:
590.B idle
591if the peer has responded to a ping recently, and we are waiting for the
592.B every
593delay before we try again; or
594.B check
595if we are currently waiting for a ping to return.
a62f8e8a 596.RE
d64ce4ae
MW
597.SP
598.BI "kick " peer
599If
600.I peer
601is currently added, and its record in the peer database contains a
602.B connect
603key (see
604.BR peers.in )
605then force a reconnection attempt. See
606.BR "Dynamic connection" .
607.SP
608.B "list-active"
a62f8e8a
MW
609Output a list of peers in the database. For each peer name
610.IR peer ,
611a line
612.RS
613.IP
614.B INFO
615.I peer
616.PP
617is output.
618.RE
619.SP
620.BI "passive \fR[" options "\fR]\fP " user
621If the database contains a user record mapping
622.I user
623to some
624.I peer
625then an
626.B INFO
627line is written containing a freshly chosen challenge string. If the
628server receives a
629.BR GREET ing
630message quoting this challenge within 30 seconds, the
631.B connect
632service will issue an
633.B ADD
634request for the peer, as for the
635.B active
636command, except that the origin of the
637.BR GREET ing
638packet is used as the peer's address.
639.RS
640.\"+opts
641.PP
642The following option is recognized.
643.TP
644.BI "\-timeout " time
645Wait for
646.I time
647instead of 30 seconds. The
648.I time
649is expressed as a non-negative integer followed by
650.BR d ,
651.BR h ,
652.BR m ,
653or
654.B s
655for days, hours, minutes or seconds respectively; if no suffix is given,
656seconds are assumed.
657.\"-opts
658.RE
d3731285 659.SP
965eb987
MW
660.BI "sabotage " peer
661Sabotage the
662.I peer
663so that
664.B connect
665thinks that it can't respond to pings. This will usually provoke a
666reconnection attempt. Use
667.B kick
668instead unless you're trying to test
669.BR connect .
670.SP
d3731285
MW
671.BI "userpeer " user
672Output a single
673.B INFO
674line identifying the peer corresponding to the
675.I user
676name.
a62f8e8a
MW
677.
678.\"--------------------------------------------------------------------------
d64ce4ae 679.SH "NOTIFICATIONS"
a62f8e8a 680.
d64ce4ae
MW
681.\"* 30 Notification broadcasts (NOTE codes)
682All notifications issued by
683.B connect
684begin with the tokens
685.BR "USER connect" .
a62f8e8a 686.SP
d64ce4ae
MW
687.B "USER connect peerdb-update"
688The peer database has changed. Other interested clients should reopen
689the database.
a62f8e8a 690.SP
d64ce4ae
MW
691.BI "USER connect ping-failed " peer " " error\fR...
692An attempt to
693.B PING
694the named
a62f8e8a 695.I peer
d64ce4ae
MW
696failed; the server replied
697.B FAIL
698.IR error ...
a62f8e8a 699.SP
d64ce4ae 700.BI "USER connect " process\fR... " stdout " line
a62f8e8a 701The
d64ce4ae
MW
702.I process
703spawned by the
704.B connect
705service unexpectedly wrote
706.I line
707to its standard output.
a62f8e8a
MW
708.
709.\"--------------------------------------------------------------------------
710.SH "WARNINGS"
711.
712.\"* 40 Warning broadcasts (WARN codes)
713All warnings issued by
714.B connect
715begin with the tokens
716.BR "USER connect" .
717.SP
718.BI "USER connect auto-add-failed " name " " error\fR...
719The attempt to add the peer
720.I name
721automatically failed: the
722.B ADD
723command reported
724.B FAIL
725.IR error ...
d64ce4ae
MW
726.SP
727.BI "USER connect ping-ok " peer
728A reply was received to a
729.B PING
730sent to the
731.IR peer ,
732though earlier attempts had failed.
733.SP
734.BI "USER connect ping-timeout " peer " attempt " i " of " n
735No reply was received to a
736.B PING
737sent to the
738.IR peer .
739So far,
740.I i
741.BR PING s
742have been sent; if a total of
743.I n
744consecutive attempts time out, the
745.B connect
746service will take further action.
747.SP
748.B "USER connect reconnecting " peer
749The dynamically connected
750.I peer
751seems to be unresponsive. The
752.B connect
753service will attempt to reconnect.
754.SP
755.BI "USER connect " process\fR... " stderr " line
756The
757.I process
758spawned by the
759.B connect
760service wrote
761.I line
762to its standard error.
763.SP
764.BI "USER connect " process\fR... " exit-nonzero " code
765The
766.I process
767spawned by the
768.B connect
769service exited with the nonzero status
770.IR code .
771.SP
772.BI "USER connect " process\fR... " exit-signal S" code
773The
774.I process
775spawned by the
776.B connect
777service was killed by signal
778.IR code .
779Here,
780.I code
781is the numeric value of the fatal signal.
782.SP
783.BI "USER connect " process\fR... " exit-unknown " status
784The
785.I process
786spawned by the
787.B connect
788service exited with an unknown
789.IR status .
790Here,
791.I status
792is the raw exit status, as returned by
793.BR waitpid (2),
794in hexadecimal.
795.
796.\"--------------------------------------------------------------------------
797.SH "CHILD PROCESS IDENTIFIERS"
798.
799.\"* 50 Child process identifiers
800Some of the warnings and notifications refer to processes spawned by
801.B connect
802under various circumstances. The process identifiers are as follows.
803.SP
804.BI "connect " peer
805A child spawned in order to establish a dynamic connection with
806.IR peer .
807.SP
808.BI "disconnect " peer
809A child spawned in order to shut down a dynamic connection with
810.IR peer .
811.SP
812.BI "ifdown " peer
813A child spawned to deconfigure the network interface for
814.IR peer .
815.SP
816.BI "ifup " peer
817A child spawned to configure the network interface for
818.IR peer .
a62f8e8a
MW
819.
820.\"--------------------------------------------------------------------------
821.SH "SUMMARY"
822.
823.\"= summary
824.
825.\"--------------------------------------------------------------------------
826.SH "SEE ALSO"
827.
828.BR tripe-service (7),
829.BR peers.in (5),
a62f8e8a
MW
830.BR tripe (8).
831.
832.\"--------------------------------------------------------------------------
833.SH "AUTHOR"
834.
835Mark Wooding, <mdw@distorted.org.uk>
836.
837.\"----- That's all, folks --------------------------------------------------