chiark / gitweb /
Upgrade licence to GPLv3+.
[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
MW
525.BI "info " peer
526Lists the database record for the named
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.
535.RE
d64ce4ae
MW
536.SP
537.BI "kick " peer
538If
539.I peer
540is currently added, and its record in the peer database contains a
541.B connect
542key (see
543.BR peers.in )
544then force a reconnection attempt. See
545.BR "Dynamic connection" .
546.SP
547.B "list-active"
a62f8e8a
MW
548Output a list of peers in the database. For each peer name
549.IR peer ,
550a line
551.RS
552.IP
553.B INFO
554.I peer
555.PP
556is output.
557.RE
558.SP
559.BI "passive \fR[" options "\fR]\fP " user
560If the database contains a user record mapping
561.I user
562to some
563.I peer
564then an
565.B INFO
566line is written containing a freshly chosen challenge string. If the
567server receives a
568.BR GREET ing
569message quoting this challenge within 30 seconds, the
570.B connect
571service will issue an
572.B ADD
573request for the peer, as for the
574.B active
575command, except that the origin of the
576.BR GREET ing
577packet is used as the peer's address.
578.RS
579.\"+opts
580.PP
581The following option is recognized.
582.TP
583.BI "\-timeout " time
584Wait for
585.I time
586instead of 30 seconds. The
587.I time
588is expressed as a non-negative integer followed by
589.BR d ,
590.BR h ,
591.BR m ,
592or
593.B s
594for days, hours, minutes or seconds respectively; if no suffix is given,
595seconds are assumed.
596.\"-opts
597.RE
d3731285
MW
598.SP
599.BI "userpeer " user
600Output a single
601.B INFO
602line identifying the peer corresponding to the
603.I user
604name.
a62f8e8a
MW
605.
606.\"--------------------------------------------------------------------------
d64ce4ae 607.SH "NOTIFICATIONS"
a62f8e8a 608.
d64ce4ae
MW
609.\"* 30 Notification broadcasts (NOTE codes)
610All notifications issued by
611.B connect
612begin with the tokens
613.BR "USER connect" .
a62f8e8a 614.SP
d64ce4ae
MW
615.B "USER connect peerdb-update"
616The peer database has changed. Other interested clients should reopen
617the database.
a62f8e8a 618.SP
d64ce4ae
MW
619.BI "USER connect ping-failed " peer " " error\fR...
620An attempt to
621.B PING
622the named
a62f8e8a 623.I peer
d64ce4ae
MW
624failed; the server replied
625.B FAIL
626.IR error ...
a62f8e8a 627.SP
d64ce4ae 628.BI "USER connect " process\fR... " stdout " line
a62f8e8a 629The
d64ce4ae
MW
630.I process
631spawned by the
632.B connect
633service unexpectedly wrote
634.I line
635to its standard output.
a62f8e8a
MW
636.
637.\"--------------------------------------------------------------------------
638.SH "WARNINGS"
639.
640.\"* 40 Warning broadcasts (WARN codes)
641All warnings issued by
642.B connect
643begin with the tokens
644.BR "USER connect" .
645.SP
646.BI "USER connect auto-add-failed " name " " error\fR...
647The attempt to add the peer
648.I name
649automatically failed: the
650.B ADD
651command reported
652.B FAIL
653.IR error ...
d64ce4ae
MW
654.SP
655.BI "USER connect ping-ok " peer
656A reply was received to a
657.B PING
658sent to the
659.IR peer ,
660though earlier attempts had failed.
661.SP
662.BI "USER connect ping-timeout " peer " attempt " i " of " n
663No reply was received to a
664.B PING
665sent to the
666.IR peer .
667So far,
668.I i
669.BR PING s
670have been sent; if a total of
671.I n
672consecutive attempts time out, the
673.B connect
674service will take further action.
675.SP
676.B "USER connect reconnecting " peer
677The dynamically connected
678.I peer
679seems to be unresponsive. The
680.B connect
681service will attempt to reconnect.
682.SP
683.BI "USER connect " process\fR... " stderr " line
684The
685.I process
686spawned by the
687.B connect
688service wrote
689.I line
690to its standard error.
691.SP
692.BI "USER connect " process\fR... " exit-nonzero " code
693The
694.I process
695spawned by the
696.B connect
697service exited with the nonzero status
698.IR code .
699.SP
700.BI "USER connect " process\fR... " exit-signal S" code
701The
702.I process
703spawned by the
704.B connect
705service was killed by signal
706.IR code .
707Here,
708.I code
709is the numeric value of the fatal signal.
710.SP
711.BI "USER connect " process\fR... " exit-unknown " status
712The
713.I process
714spawned by the
715.B connect
716service exited with an unknown
717.IR status .
718Here,
719.I status
720is the raw exit status, as returned by
721.BR waitpid (2),
722in hexadecimal.
723.
724.\"--------------------------------------------------------------------------
725.SH "CHILD PROCESS IDENTIFIERS"
726.
727.\"* 50 Child process identifiers
728Some of the warnings and notifications refer to processes spawned by
729.B connect
730under various circumstances. The process identifiers are as follows.
731.SP
732.BI "connect " peer
733A child spawned in order to establish a dynamic connection with
734.IR peer .
735.SP
736.BI "disconnect " peer
737A child spawned in order to shut down a dynamic connection with
738.IR peer .
739.SP
740.BI "ifdown " peer
741A child spawned to deconfigure the network interface for
742.IR peer .
743.SP
744.BI "ifup " peer
745A child spawned to configure the network interface for
746.IR peer .
a62f8e8a
MW
747.
748.\"--------------------------------------------------------------------------
749.SH "SUMMARY"
750.
751.\"= summary
752.
753.\"--------------------------------------------------------------------------
754.SH "SEE ALSO"
755.
756.BR tripe-service (7),
757.BR peers.in (5),
a62f8e8a
MW
758.BR tripe (8).
759.
760.\"--------------------------------------------------------------------------
761.SH "AUTHOR"
762.
763Mark Wooding, <mdw@distorted.org.uk>
764.
765.\"----- That's all, folks --------------------------------------------------