Add new `knock' protocol.
[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.\"--------------------------------------------------------------------------
cd450424 26.so ../common/defs.man \"@@@PRE@@@
a62f8e8a
MW
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"
8362ac1c
MW
249The
250.B connect
251service supports two kinds of dynamic connection.
252.PP
253The new kind of dynamic association uses the built-in
254.B knock
255protocol. If the peer's database record assigns a value to the
256.B knock
257key, then the new connection protocol is used: this value is sent to the
258peer during key-exchange, which should (if the peer is properly
259configured) automatically establish the other end of the connection.
260The string should have the form
261.RI [ prefix\fB. ] tag ,
262where the whole string names this host as it is known by the remote
263host, and the
264.I tag
265names this host's public key. The passive server receives this string,
266verifies that the sender has access to the claimed private key, and
267emits a
268.B KNOCK
269notification which
270.B connect
271notices, causing it to establish the passive peer. While the internals
272are somewhat complex, configuration is pretty easy.
273.PP
274The older kind of dynamic association is rather more complicated to set
275up, and involves running shell commands, and probably configuring SSH.
d64ce4ae
MW
276If a peer's database record assigns a value to the
277.B connect
278key, then the
279.B connect
280service will attempt to establish a connection dynamically with the
281peer. The value of the
282.B connect
283key is invoked as a Bourne shell command, i.e.,
284.IP
285.B /bin/sh \-c
286.I connect
287.PP
288is executed. The command is expected to contact the remote server and
289report, on standard output, a challenge string, typically by issuing
290a
291.B passive
292command to the instance of the
293.B connect
294service running on the peer. The
295.B connect
296service reads this challenge, and submits the command
297.IP
298.B GREET
299.I peer
300.I challenge
301.PP
302Typically, the
303.B connect
304command will issue a command such as
305.IP
306.B SVCSUBMIT connect passive
307.I our-name
308.PP
309where
310.I our-name
311is the remote peer's name for this host.
312.PP
313Similarly, if the database record has a
314.B disconnect
315entry, then
316.B connect
317will use this to give the peer explicit notification that its services
318are no longer needed. The value of the
319.B disconnect
320key is invoked as a Bourne shell command. This ought to result in a
321.B KILL
322command being issued to the peer's server.
323.PP
8362ac1c
MW
324In detail, the protocol for old-style dynamic connection works as
325follows.
a62f8e8a
MW
326.hP 1.
327The active peer
328.BR ADD s
329its partner, typically using the
330.B \-cork
331option to suppress the key-exchange message which the server usually
332sends immediately, since otherwise the passive peer will warn about it.
333.hP 2.
d64ce4ae 334The active peer issues the command
a62f8e8a
MW
335.RS
336.IP
337.B SVCSUBMIT connect passive
338.I user
339.PP
340to the passive peer's server. (Here,
341.I user
d64ce4ae
MW
342is a name identifying the active peer; see below.) Doing this is the
343responsibility of the
344.B connect
345command.
a62f8e8a
MW
346.RE
347.hP 3.
348The
349.B connect
350service on the passive peer responds with a
351.I challenge
352\(en a short Base64-encoded string. Somehow this challenge is sent back
353to the passive peer without being intercepted.
354.hP 4.
355The active peer sends a
356.BR GREET ing
357containing the challenge to its passive partner. The passive server
358announces the arrival of this message, and the originating address and
359port.
360.hP 5.
361The
362.B connect
363service running on the passive host receives the notification, matches
364it up with the
365.I user
366from the initial connection request, and
367.BR ADD s
368the appropriate peer, with the address from the
369.BR GREET ing.
d64ce4ae
MW
370.
371.SS "Operation"
372On startup,
373.B connect
374requests a list of current peers from the
375.BR tripe (8)
376server, and adopts any eligible peers. If the
377.B \-\-startup
378flag was passed on the command line, the newly adopted peers have their
379interfaces configured and connection attempts are made.
a62f8e8a 380.PP
d64ce4ae
MW
381Adopted peers are pinged at regular intervals (using the
382.B PING
383administrative command; see
384.BR tripe-admin (5)).
385This process can be configured by assigning values to keys in the peer's
386database record. Some of these parameters are time intervals,
387expressed as a nonnegative integer followed optionally by
388.BR d ,
389.BR h ,
390.BR m ,
391or
392.B s
393for days, hours, minutes, or seconds, respectively; if no suffix is
394given, seconds are assumed.
395.PP
396The parameters are as follows.
397.TP
398.B every
399A time interval: how often to ping the peer to ensure that it's still
02c99524
MW
400alive. The default is 30 seconds for active dynamic peers, and 5
401minutes for passive peers.
402.IP
403The period for dynamic peers should be no longer than
404.I timeout
405\(mu
406.RI ( retries
407\- 1). Consider an idle mobile peer which has its IP address changed
408just before its passive peer begins pinging. The static peer's pings
409will go to the old address until it receives a ping back from the mobile
410peer. Therefore, the static peer has to keep pinging until it would
411definitely have received an unsolicited ping from the mobile peer, and
412therefore be informed of the change of address. And it's no use
413learning about the change of address just after sending the last ping to
414the old address, so the last retry doesn't count for the purposes of
415this calculation.
416.IP
417Besides, the consequences of failed pinging differ between dynamic and
418passive peers. In the former case, a failure provokes a reconnection
419attempt, after which (hopefully) things will work again: it's probably a
420good thing to check frequently and fail fast. In the latter case, the
421dynamic peer will certainly have to notice that it's been abandoned and
422arrange to retry, causing a communication failure where maybe there
423wasn't really one before.
d64ce4ae
MW
424.TP
425.B timeout
426A time interval: how long to wait for a reply before retrying or giving
427up. The default is 10 seconds.
428.TP
429.B retries
430An integer: how many failed attempts to make before deciding that the
431peer is unreachable and taking action. The default is 5 attempts.
432.PP
433The algorithm is as follows. Send up to
434.I retries
435pings; if a reply is received before the
436.I timeout
437then the peer is alive; wait
438.I every
439and check again. If no reply is received within the
440.IR timeout ,
441then try again up to
442.I retries
443times. If no attempt succeeds, the peer is declared unreachable. If
444the peer has a
445.B connect
446command (i.e., it connects dynamically) then another connection attempt
447is made. Otherwise the peer is killed.
a62f8e8a
MW
448.
449.\"--------------------------------------------------------------------------
450.SH "SERVICE COMMAND REFERENCE"
451.
452.\"* 10 Service commands
453The commands provided by the service are as follows.
454.SP
455.BI "active " peer
456Make an active connection to the named
457.IR peer .
458The service will submit the command
459.RS
460.IP
461.B ADD
462.RB [ \-cork ]
463.RB [ \-keepalive
464.IR time ]
48b84569
MW
465.RB [ \-key
466.IR tag ]
d64ce4ae
MW
467.RB [ \-priv
468.IR tag ]
6411163d 469.RB [ \-mobile ]
a62f8e8a
MW
470.RB [ \-tunnel
471.IR driver ]
472.I address
473.PP
474Specifically:
475.hP \*o
476The option
477.B \-cork
478is provided if the peer's database record assigns the
479.B cork
480key one of the values
481.BR t ,
482.BR true ,
483.BR y ,
484.BR yes,
485or
486.BR on .
487.hP \*o
488The option
489.B \-keepalive
490.I time
491is provided if the database record assigns a value
492.I time
493to the
494.B keepalive
495key.
496.hP \*o
497The option
48b84569
MW
498.B \-key
499.I tag
500is provided if the database record assigns a value
501.I tag
502to the
503.B key
504key.
505.hP \*o
506The option
d64ce4ae
MW
507.B \-priv
508.I tag
509is provided if the database record assigns a value
510.I tag
511to the
512.B priv
513key.
514.hP \*o
515The option
6411163d
MW
516.B \-mobile
517is provided if the peer's database record assigns the
518.B mobile
519key one of the values
520.BR t ,
521.BR true ,
522.BR y ,
523.BR yes,
524or
525.BR on .
526.hP \*o
527The option
a62f8e8a
MW
528.B \-tunnel
529.I driver
530is provided if the database record assigns a value
531.I driver
532to the
533.B tunnel
534key.
535.hP \*o
536The
537.I address
538is the value assigned to the
539.B peer
540key in the database record.
541.RE
542.SP
d64ce4ae
MW
543.B adopted
544For each peer being tracked by the
545.B connect
546service, write a line
547.B INFO
548.IR name .
549(Compatibility note: it's possible that further information will be
550provided about each peer, in the form of subsequent tokens. Clients
551should be prepared to ignore such tokens.)
552.SP
a62f8e8a 553.BI "info " peer
b9dedfa6 554Lists the database record and additional information about the named
a62f8e8a
MW
555.IR peer .
556For each key/value pair, a line
557.RS
558.IP
559.B INFO
560.IB key = value
561.PP
562is output. The key/value pairs are output in an arbitrary order.
b9dedfa6
MW
563.PP
564In addition to the fields of the peer's database record, the following
565additional keys are defined.
566.TP
567.B failures
568The number of failed pings in the current or most recent batch, in
569decimal.
570.TP
571.B last-ping
572The round-trip time of the most recent ping in milliseconds, in the form
573.IB nn.n ms\fR,
574or
575.B timeout
576if the most recent ping timed out,
577or
578.B \-
579if no pings have yet completed.
580.TP
581.B max-ping
582The maximum successful ping time 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 mean-ping
589The average successful ping time so far in milliseconds, in the form
590.IB nn.n ms\fR,
591or
592.B \-
593if no pings have yet succeeded.
594.TP
595.B min-ping
596The minimum successful ping time so far in milliseconds, in the form
597.IB nn.n ms\fR,
598or
599.B \-
600if no pings have yet succeeded.
601.TP
602.B n-lost
603The number of pings which have been declared timed out so far, in
604decimal.
605.TP
606.B n-ping
607The number of successful pings so far, in decimal.
608.TP
609.B sd-ping
610The standard deviation of ping times so far in milliseconds, in the form
611.IB nn.n ms\fR,
612or
613.B \-
614if no pings have yet succeeded.
615.TP
616.B state
617One of the strings:
618.B idle
619if the peer has responded to a ping recently, and we are waiting for the
620.B every
621delay before we try again; or
622.B check
623if we are currently waiting for a ping to return.
a62f8e8a 624.RE
d64ce4ae
MW
625.SP
626.BI "kick " peer
627If
628.I peer
629is currently added, and its record in the peer database contains a
630.B connect
631key (see
632.BR peers.in )
633then force a reconnection attempt. See
634.BR "Dynamic connection" .
635.SP
636.B "list-active"
a62f8e8a
MW
637Output a list of peers in the database. For each peer name
638.IR peer ,
639a line
640.RS
641.IP
642.B INFO
643.I peer
644.PP
645is output.
646.RE
647.SP
648.BI "passive \fR[" options "\fR]\fP " user
649If the database contains a user record mapping
650.I user
651to some
652.I peer
653then an
654.B INFO
655line is written containing a freshly chosen challenge string. If the
656server receives a
657.BR GREET ing
658message quoting this challenge within 30 seconds, the
659.B connect
660service will issue an
661.B ADD
662request for the peer, as for the
663.B active
664command, except that the origin of the
665.BR GREET ing
666packet is used as the peer's address.
667.RS
668.\"+opts
669.PP
670The following option is recognized.
671.TP
672.BI "\-timeout " time
673Wait for
674.I time
675instead of 30 seconds. The
676.I time
677is expressed as a non-negative integer followed by
678.BR d ,
679.BR h ,
680.BR m ,
681or
682.B s
683for days, hours, minutes or seconds respectively; if no suffix is given,
684seconds are assumed.
685.\"-opts
686.RE
d3731285 687.SP
965eb987
MW
688.BI "sabotage " peer
689Sabotage the
690.I peer
691so that
692.B connect
693thinks that it can't respond to pings. This will usually provoke a
694reconnection attempt. Use
695.B kick
696instead unless you're trying to test
697.BR connect .
698.SP
d3731285
MW
699.BI "userpeer " user
700Output a single
701.B INFO
702line identifying the peer corresponding to the
703.I user
704name.
a62f8e8a
MW
705.
706.\"--------------------------------------------------------------------------
d64ce4ae 707.SH "NOTIFICATIONS"
a62f8e8a 708.
d64ce4ae
MW
709.\"* 30 Notification broadcasts (NOTE codes)
710All notifications issued by
711.B connect
712begin with the tokens
713.BR "USER connect" .
a62f8e8a 714.SP
d64ce4ae
MW
715.B "USER connect peerdb-update"
716The peer database has changed. Other interested clients should reopen
717the database.
a62f8e8a 718.SP
d64ce4ae
MW
719.BI "USER connect ping-failed " peer " " error\fR...
720An attempt to
721.B PING
722the named
a62f8e8a 723.I peer
d64ce4ae
MW
724failed; the server replied
725.B FAIL
726.IR error ...
a62f8e8a 727.SP
d64ce4ae 728.BI "USER connect " process\fR... " stdout " line
a62f8e8a 729The
d64ce4ae
MW
730.I process
731spawned by the
732.B connect
733service unexpectedly wrote
734.I line
735to its standard output.
a62f8e8a
MW
736.
737.\"--------------------------------------------------------------------------
738.SH "WARNINGS"
739.
740.\"* 40 Warning broadcasts (WARN codes)
741All warnings issued by
742.B connect
743begin with the tokens
744.BR "USER connect" .
745.SP
746.BI "USER connect auto-add-failed " name " " error\fR...
747The attempt to add the peer
748.I name
749automatically failed: the
750.B ADD
751command reported
752.B FAIL
753.IR error ...
d64ce4ae 754.SP
8362ac1c
MW
755.BI "USER connect knock-active-peer " name
756The server reported a valid
757.B knock
758message from a peer calling itself
759.I name
760but this is not a passive peer.
761.SP
762.BI "USER connect knock-unknown-peer " name
763The server reported a valid
764.B knock
765message from a peer calling itself
766.I name
767but no such peer is defined in the database.
768.SP
769.BI "USER connect knock-tag-mismatch peer " name " public-key-tag " tag
770The server reported a valid
771.B knock
772message from a peer calling itself
773.I name
774but this name doesn't match that peer's recorded public-key tag, which
775is
776.IR tag .
777.SP
d64ce4ae
MW
778.BI "USER connect ping-ok " peer
779A reply was received to a
780.B PING
781sent to the
782.IR peer ,
783though earlier attempts had failed.
784.SP
785.BI "USER connect ping-timeout " peer " attempt " i " of " n
786No reply was received to a
787.B PING
788sent to the
789.IR peer .
790So far,
791.I i
792.BR PING s
793have been sent; if a total of
794.I n
795consecutive attempts time out, the
796.B connect
797service will take further action.
798.SP
799.B "USER connect reconnecting " peer
800The dynamically connected
801.I peer
802seems to be unresponsive. The
803.B connect
804service will attempt to reconnect.
805.SP
806.BI "USER connect " process\fR... " stderr " line
807The
808.I process
809spawned by the
810.B connect
811service wrote
812.I line
813to its standard error.
814.SP
815.BI "USER connect " process\fR... " exit-nonzero " code
816The
817.I process
818spawned by the
819.B connect
820service exited with the nonzero status
821.IR code .
822.SP
823.BI "USER connect " process\fR... " exit-signal S" code
824The
825.I process
826spawned by the
827.B connect
828service was killed by signal
829.IR code .
830Here,
831.I code
832is the numeric value of the fatal signal.
833.SP
834.BI "USER connect " process\fR... " exit-unknown " status
835The
836.I process
837spawned by the
838.B connect
839service exited with an unknown
840.IR status .
841Here,
842.I status
843is the raw exit status, as returned by
844.BR waitpid (2),
845in hexadecimal.
846.
847.\"--------------------------------------------------------------------------
848.SH "CHILD PROCESS IDENTIFIERS"
849.
850.\"* 50 Child process identifiers
851Some of the warnings and notifications refer to processes spawned by
852.B connect
853under various circumstances. The process identifiers are as follows.
854.SP
855.BI "connect " peer
856A child spawned in order to establish a dynamic connection with
857.IR peer .
858.SP
859.BI "disconnect " peer
860A child spawned in order to shut down a dynamic connection with
861.IR peer .
862.SP
863.BI "ifdown " peer
864A child spawned to deconfigure the network interface for
865.IR peer .
866.SP
867.BI "ifup " peer
868A child spawned to configure the network interface for
869.IR peer .
a62f8e8a
MW
870.
871.\"--------------------------------------------------------------------------
872.SH "SUMMARY"
873.
874.\"= summary
875.
876.\"--------------------------------------------------------------------------
877.SH "SEE ALSO"
878.
879.BR tripe-service (7),
880.BR peers.in (5),
a62f8e8a
MW
881.BR tripe (8).
882.
883.\"--------------------------------------------------------------------------
884.SH "AUTHOR"
885.
886Mark Wooding, <mdw@distorted.org.uk>
887.
888.\"----- That's all, folks --------------------------------------------------