server/{keyexch.c,keyset.c}: Move timing parameters to tripe.h.
[tripe] / server / tripe.h
CommitLineData
410c8acf 1/* -*-c-*-
2 *
410c8acf 3 * Main header file for TrIPE
4 *
5 * (c) 2001 Straylight/Edgeware
6 */
7
e04c2d50 8/*----- Licensing notice --------------------------------------------------*
410c8acf 9 *
10 * This file is part of Trivial IP Encryption (TrIPE).
11 *
12 * TrIPE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
e04c2d50 16 *
410c8acf 17 * TrIPE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
e04c2d50 21 *
410c8acf 22 * You should have received a copy of the GNU General Public License
23 * along with TrIPE; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
410c8acf 27#ifndef TRIPE_H
28#define TRIPE_H
29
30#ifdef __cplusplus
31 extern "C" {
32#endif
33
34/*----- Header files ------------------------------------------------------*/
35
73189848 36#include "config.h"
37
410c8acf 38#include <assert.h>
39#include <ctype.h>
40#include <errno.h>
b9066fbb 41#include <limits.h>
410c8acf 42#include <signal.h>
43#include <stdarg.h>
44#include <stddef.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48#include <time.h>
49
50#include <sys/types.h>
51#include <sys/time.h>
52#include <unistd.h>
53#include <fcntl.h>
54#include <sys/stat.h>
388e0319 55#include <sys/wait.h>
410c8acf 56
57#include <sys/socket.h>
58#include <sys/un.h>
59#include <netinet/in.h>
60#include <arpa/inet.h>
61#include <netdb.h>
62
63#include <pwd.h>
64#include <grp.h>
65
66#include <mLib/alloc.h>
67#include <mLib/arena.h>
37941236 68#include <mLib/base64.h>
410c8acf 69#include <mLib/bres.h>
19dd2531 70#include <mLib/daemonize.h>
410c8acf 71#include <mLib/dstr.h>
72#include <mLib/env.h>
73#include <mLib/fdflags.h>
388e0319 74#include <mLib/fdpass.h>
410c8acf 75#include <mLib/fwatch.h>
c8e02c8a 76#include <mLib/hash.h>
165efde7 77#include <mLib/macros.h>
b9537f3b 78#include <mLib/mdup.h>
410c8acf 79#include <mLib/mdwopt.h>
80#include <mLib/quis.h>
81#include <mLib/report.h>
82#include <mLib/sel.h>
83#include <mLib/selbuf.h>
84#include <mLib/sig.h>
85#include <mLib/str.h>
86#include <mLib/sub.h>
87#include <mLib/trace.h>
0ba8de86 88#include <mLib/tv.h>
19dd2531 89#include <mLib/versioncmp.h>
410c8acf 90
165db1a8 91#include <catacomb/buf.h>
92
410c8acf 93#include <catacomb/gcipher.h>
94#include <catacomb/gmac.h>
95#include <catacomb/grand.h>
96#include <catacomb/key.h>
97#include <catacomb/paranoia.h>
98
410c8acf 99#include <catacomb/noise.h>
100#include <catacomb/rand.h>
410c8acf 101
102#include <catacomb/mp.h>
410c8acf 103#include <catacomb/mprand.h>
104#include <catacomb/dh.h>
52c03a2a 105#include <catacomb/ec.h>
106#include <catacomb/ec-keys.h>
107#include <catacomb/group.h>
410c8acf 108
388e0319 109#include "priv.h"
78698994 110#include "protocol.h"
10f681b1 111#include "slip.h"
410c8acf 112#include "util.h"
113
114#undef sun
115
116/*----- Magic numbers -----------------------------------------------------*/
117
410c8acf 118/* --- Trace flags --- */
119
120#define T_TUNNEL 1u
121#define T_PEER 2u
122#define T_PACKET 4u
123#define T_ADMIN 8u
124#define T_CRYPTO 16u
125#define T_KEYSET 32u
126#define T_KEYEXCH 64u
127#define T_KEYMGMT 128u
37941236 128#define T_CHAL 256u
388e0319 129/* T_PRIVSEP in priv.h */
410c8acf 130
388e0319 131#define T_ALL 1023u
410c8acf 132
133/* --- Units --- */
134
135#define SEC(n) (n##u)
136#define MIN(n) (n##u * 60u)
137#define MEG(n) (n##ul * 1024ul * 1024ul)
138
e9fac70c
MW
139/* --- Timing parameters --- */
140
141#define T_EXP MIN(60) /* Expiry time for a key */
142#define T_REGEN MIN(40) /* Regeneration time for a key */
143
144#define T_VALID SEC(20) /* Challenge validity period */
145#define T_RETRY SEC(10) /* Challenge retransmit interval */
146
410c8acf 147/* --- Other things --- */
148
149#define PKBUFSZ 65536
150
832a2ab6 151/*----- Cipher selections -------------------------------------------------*/
152
b5c45da1 153typedef struct algswitch {
154 const gccipher *c; /* Symmetric encryption scheme */
155 const gccipher *mgf; /* Mask-generation function */
156 const gchash *h; /* Hash function */
157 const gcmac *m; /* Message authentication code */
158 size_t hashsz; /* Hash output size */
159 size_t tagsz; /* Length to truncate MAC tags */
383a9d71 160 size_t expsz; /* Size of data to process */
b5c45da1 161 size_t cksz, mksz; /* Key lengths for @c@ and @m@ */
162} algswitch;
832a2ab6 163
b5c45da1 164extern algswitch algs;
832a2ab6 165
b5c45da1 166#define MAXHASHSZ 64 /* Largest possible hash size */
832a2ab6 167
b5c45da1 168#define HASH_STRING(h, s) GH_HASH((h), (s), sizeof(s))
410c8acf 169
aeeb5611 170/*----- Data structures ---------------------------------------------------*/
410c8acf 171
172/* --- Socket addresses --- *
173 *
174 * A magic union of supported socket addresses.
175 */
176
177typedef union addr {
178 struct sockaddr sa;
179 struct sockaddr_in sin;
180} addr;
181
c8e02c8a
MW
182/* --- Mapping keyed on addresses --- */
183
184typedef struct addrmap {
185 hash_table t;
186 size_t load;
187} addrmap;
188
189typedef struct addrmap_base {
190 hash_base b;
191 addr a;
192} addrmap_base;
193
37941236 194/* --- Sequence number checking --- */
195
196typedef struct seqwin {
197 uint32 seq; /* First acceptable input sequence */
198 uint32 win; /* Window of acceptable numbers */
199} seqwin;
200
201#define SEQ_WINSZ 32 /* Bits in sequence number window */
202
410c8acf 203/* --- A symmetric keyset --- *
204 *
205 * A keyset contains a set of symmetric keys for encrypting and decrypting
206 * packets. Keysets are stored in a list, sorted in reverse order of
207 * creation, so that the most recent keyset (the one most likely to be used)
208 * is first.
209 *
210 * Each keyset has a time limit and a data limit. The keyset is destroyed
211 * when either it has existed for too long, or it has been used to encrypt
212 * too much data. New key exchanges are triggered when keys are close to
213 * expiry.
214 */
215
216typedef struct keyset {
217 struct keyset *next; /* Next active keyset in the list */
832a2ab6 218 unsigned ref; /* Reference count for keyset */
9466fafa 219 struct peer *p; /* Pointer to peer structure */
410c8acf 220 time_t t_exp; /* Expiry time for this keyset */
383a9d71 221 unsigned long sz_exp, sz_regen; /* Data limits for the keyset */
832a2ab6 222 T( unsigned seq; ) /* Sequence number for tracing */
223 unsigned f; /* Various useful flags */
e04c2d50 224 gcipher *cin, *cout; /* Keyset ciphers for encryption */
b5c45da1 225 size_t tagsz; /* Length to truncate MAC tags */
e04c2d50 226 gmac *min, *mout; /* Keyset MACs for integrity */
1484d822 227 uint32 oseq; /* Outbound sequence number */
37941236 228 seqwin iseq; /* Inbound sequence number */
410c8acf 229} keyset;
230
832a2ab6 231#define KSF_LISTEN 1u /* Don't encrypt packets yet */
232#define KSF_LINK 2u /* Key is in a linked list */
233
a50f9a0e
MW
234#define KSERR_REGEN -1 /* Regenerate keys */
235#define KSERR_NOKEYS -2 /* No keys left */
236#define KSERR_DECRYPT -3 /* Unable to decrypt message */
12a26b8b
MW
237#define KSERR_SEQ -4 /* Incorrect sequence number */
238#define KSERR_MALFORMED -5 /* Input ciphertext is broken */
a50f9a0e 239
410c8acf 240/* --- Key exchange --- *
241 *
242 * TrIPE uses the Wrestlers Protocol for its key exchange. The Wrestlers
243 * Protocol has a number of desirable features (e.g., perfect forward
244 * secrecy, and zero-knowledge authentication) which make it attractive for
245 * use in TrIPE. The Wrestlers Protocol was designed by Mark Wooding and
246 * Clive Jones.
247 */
248
832a2ab6 249#define KX_NCHAL 16u
832a2ab6 250
251typedef struct kxchal {
252 struct keyexch *kx; /* Pointer back to key exchange */
52c03a2a 253 ge *c; /* Responder's challenge */
254 ge *r; /* My reply to the challenge */
832a2ab6 255 keyset *ks; /* Pointer to temporary keyset */
256 unsigned f; /* Various useful flags */
257 sel_timer t; /* Response timer for challenge */
b5c45da1 258 octet hc[MAXHASHSZ]; /* Hash of his challenge */
de7bd20b 259 octet ck[MAXHASHSZ]; /* His magical check value */
b5c45da1 260 octet hswrq_in[MAXHASHSZ]; /* Inbound switch request message */
261 octet hswok_in[MAXHASHSZ]; /* Inbound switch confirmation */
262 octet hswrq_out[MAXHASHSZ]; /* Outbound switch request message */
263 octet hswok_out[MAXHASHSZ]; /* Outbound switch confirmation */
832a2ab6 264} kxchal;
265
410c8acf 266typedef struct keyexch {
410c8acf 267 struct peer *p; /* Pointer back to the peer */
832a2ab6 268 keyset **ks; /* Peer's list of keysets */
410c8acf 269 unsigned f; /* Various useful flags */
832a2ab6 270 unsigned s; /* Current state in exchange */
410c8acf 271 sel_timer t; /* Timer for next exchange */
52c03a2a 272 ge *kpub; /* Peer's public key */
00e64b67 273 time_t texp_kpub; /* Expiry time for public key */
832a2ab6 274 mp *alpha; /* My temporary secret */
52c03a2a 275 ge *c; /* My challenge */
276 ge *rx; /* The expected response */
832a2ab6 277 unsigned nr; /* Number of extant responses */
410c8acf 278 time_t t_valid; /* When this exchange goes bad */
b5c45da1 279 octet hc[MAXHASHSZ]; /* Hash of my challenge */
832a2ab6 280 kxchal *r[KX_NCHAL]; /* Array of challenges */
410c8acf 281} keyexch;
282
283#define KXF_TIMER 1u /* Waiting for a timer to go off */
00e64b67 284#define KXF_DEAD 2u /* The key-exchanger isn't up */
285#define KXF_PUBKEY 4u /* Key exchanger has a public key */
010e6f63 286#define KXF_CORK 8u /* Don't send anything yet */
832a2ab6 287
288enum {
289 KXS_DEAD, /* Uninitialized state (magical) */
290 KXS_CHAL, /* Main answer-challenges state */
291 KXS_COMMIT, /* Committed: send switch request */
292 KXS_SWITCH /* Switched: send confirmation */
293};
410c8acf 294
295/* --- Tunnel structure --- *
296 *
297 * Used to maintain system-specific information about the tunnel interface.
298 */
299
42da2a58 300typedef struct tunnel tunnel;
301struct peer;
110d564e 302
42da2a58 303typedef struct tunnel_ops {
304 const char *name; /* Name of this tunnel driver */
388e0319
MW
305 unsigned flags; /* Various interesting flags */
306#define TUNF_PRIVOPEN 1u /* Need helper to open file */
42da2a58 307 void (*init)(void); /* Initializes the system */
eb5f3fea 308 tunnel *(*create)(struct peer */*p*/, int /*fd*/, char **/*ifn*/);
72917fe7
MW
309 /* Initializes a new tunnel */
310 void (*setifname)(tunnel */*t*/, const char */*ifn*/);
311 /* Notifies ifname change */
42da2a58 312 void (*inject)(tunnel */*t*/, buf */*b*/); /* Sends packet through if */
313 void (*destroy)(tunnel */*t*/); /* Destroys a tunnel */
314} tunnel_ops;
b9066fbb 315
42da2a58 316#ifndef TUN_INTERNALS
317struct tunnel { const tunnel_ops *ops; };
410c8acf 318#endif
410c8acf 319
832a2ab6 320/* --- Peer statistics --- *
321 *
322 * Contains various interesting and not-so-interesting statistics about a
323 * peer. This is updated by various parts of the code. The format of the
324 * structure isn't considered private, and @p_stats@ returns a pointer to the
325 * statistics block for a given peer.
326 */
327
328typedef struct stats {
329 unsigned long sz_in, sz_out; /* Size of all data in and out */
330 unsigned long sz_kxin, sz_kxout; /* Size of key exchange messages */
331 unsigned long sz_ipin, sz_ipout; /* Size of encapsulated IP packets */
3cdc3f3a 332 time_t t_start, t_last, t_kx; /* Time peer created, last pk, kx */
832a2ab6 333 unsigned long n_reject; /* Number of rejected packets */
334 unsigned long n_in, n_out; /* Number of packets in and out */
335 unsigned long n_kxin, n_kxout; /* Number of key exchange packets */
336 unsigned long n_ipin, n_ipout; /* Number of encrypted packets */
337} stats;
338
410c8acf 339/* --- Peer structure --- *
340 *
341 * The main structure which glues everything else together.
342 */
343
0ba8de86 344typedef struct peerspec {
345 char *name; /* Peer's name */
48b84569 346 char *tag; /* Public key tag */
0ba8de86 347 const tunnel_ops *tops; /* Tunnel operations */
348 unsigned long t_ka; /* Keep alive interval */
349 addr sa; /* Socket address to speak to */
350 size_t sasz; /* Socket address size */
8743c776 351 unsigned f; /* Flags for the peer */
6411163d
MW
352#define PSF_KXMASK 255u /* Key-exchange flags to set */
353#define PSF_MOBILE 256u /* Address may change rapidly */
0ba8de86 354} peerspec;
355
c8e02c8a
MW
356typedef struct peer_byname {
357 sym_base _b;
358 struct peer *p;
359} peer_byname;
360
361typedef struct peer_byaddr {
362 addrmap_base _b;
363 struct peer *p;
364} peer_byaddr;
365
410c8acf 366typedef struct peer {
c8e02c8a
MW
367 peer_byname *byname; /* Lookup-by-name block */
368 peer_byaddr *byaddr; /* Lookup-by-address block */
0ba8de86 369 struct ping *pings; /* Pings we're waiting for */
370 peerspec spec; /* Specifications for this peer */
42da2a58 371 tunnel *t; /* Tunnel for local packets */
64cf2223 372 char *ifname; /* Interface name for tunnel */
410c8acf 373 keyset *ks; /* List head for keysets */
410c8acf 374 buf b; /* Buffer for sending packets */
832a2ab6 375 stats st; /* Statistics */
376 keyexch kx; /* Key exchange protocol block */
0ba8de86 377 sel_timer tka; /* Timer for keepalives */
410c8acf 378} peer;
379
c8e02c8a
MW
380typedef struct peer_iter { sym_iter i; } peer_iter;
381
0ba8de86 382typedef struct ping {
383 struct ping *next, *prev; /* Links to next and previous */
384 peer *p; /* Peer so we can free it */
385 unsigned msg; /* Kind of response expected */
386 uint32 id; /* Id so we can recognize response */
387 octet magic[32]; /* Some random data */
388 sel_timer t; /* Timeout for ping */
389 void (*func)(int /*rc*/, void */*arg*/); /* Function to call when done */
390 void *arg; /* Argument for callback */
391} ping;
392
393enum {
394 PING_NONOTIFY = -1,
395 PING_OK = 0,
396 PING_TIMEOUT,
397 PING_PEERDIED,
398 PING_MAX
399};
400
410c8acf 401/* --- Admin structure --- */
402
fd3cf232 403#define OBUFSZ 16384u
404
405typedef struct obuf {
406 struct obuf *next; /* Next buffer in list */
407 char *p_in, *p_out; /* Pointers into the buffer */
408 char buf[OBUFSZ]; /* The actual buffer */
409} obuf;
410
de014da6 411typedef struct oqueue {
412 obuf *hd, *tl; /* Head and tail pointers */
413} oqueue;
414
415struct admin;
416
417typedef struct admin_bgop {
418 struct admin_bgop *next, *prev; /* Links to next and previous */
419 struct admin *a; /* Owner job */
420 char *tag; /* Tag string for messages */
421 void (*cancel)(struct admin_bgop *); /* Destructor function */
422} admin_bgop;
423
37941236 424typedef struct admin_resop {
de014da6 425 admin_bgop bg; /* Background operation header */
37941236 426 char *addr; /* Hostname to be resolved */
de014da6 427 bres_client r; /* Background resolver task */
428 sel_timer t; /* Timer for resolver */
37941236 429 addr sa; /* Socket address */
430 size_t sasz; /* Socket address size */
431 void (*func)(struct admin_resop *, int); /* Handler */
432} admin_resop;
433
434enum { ARES_OK, ARES_FAIL };
435
436typedef struct admin_addop {
437 admin_resop r; /* Name resolution header */
438 peerspec peer; /* Peer pending creation */
de014da6 439} admin_addop;
440
441typedef struct admin_pingop {
442 admin_bgop bg; /* Background operation header */
443 ping ping; /* Ping pending response */
444 struct timeval pingtime; /* Time last ping was sent */
be6a1b7a
MW
445} admin_pingop;
446
447typedef struct admin_service {
448 sym_base _b; /* Hash table base structure */
449 char *version; /* The provided version */
450 struct admin *prov; /* Which client provides me */
451 struct admin_service *next, *prev; /* Client's list of services */
452} admin_service;
de014da6 453
5d46c0f8
MW
454typedef struct admin_svcop {
455 admin_bgop bg; /* Background operation header */
456 struct admin *prov; /* Client servicing this job */
cc921fba 457 unsigned index; /* This job's index */
5d46c0f8
MW
458 struct admin_svcop *next, *prev; /* Links for provider's jobs */
459} admin_svcop;
460
461typedef struct admin_jobentry {
462 unsigned short seq; /* Zero if unused */
463 union {
464 admin_svcop *op; /* Operation, if slot in use, ... */
465 uint32 next; /* ... or index of next free slot */
466 } u;
467} admin_jobentry;
468
469typedef struct admin_jobtable {
470 uint32 n, sz; /* Used slots and table size */
471 admin_svcop *active; /* List of active jobs */
472 uint32 free; /* Index of first free slot */
473 admin_jobentry *v; /* And the big array of entries */
474} admin_jobtable;
475
410c8acf 476typedef struct admin {
477 struct admin *next, *prev; /* Links to next and previous */
fd3cf232 478 unsigned f; /* Various useful flags */
060ca767 479 unsigned ref; /* Reference counter */
410c8acf 480#ifndef NTRACE
481 unsigned seq; /* Sequence number for tracing */
482#endif
de014da6 483 oqueue out; /* Output buffer list */
484 oqueue delay; /* Delayed output buffer list */
485 admin_bgop *bg; /* Backgrounded operations */
be6a1b7a 486 admin_service *svcs; /* Which services I provide */
5d46c0f8 487 admin_jobtable j; /* Table of outstanding jobs */
fd3cf232 488 selbuf b; /* Line buffer for commands */
489 sel_file w; /* Selector for write buffering */
410c8acf 490} admin;
491
fd3cf232 492#define AF_DEAD 1u /* Destroy this admin block */
060ca767 493#define AF_CLOSE 2u /* Client closed connection */
3cdc3f3a 494#define AF_NOTE 4u /* Catch notifications */
de014da6 495#define AF_WARN 8u /* Catch warning messages */
3cdc3f3a 496#ifndef NTRACE
de014da6 497 #define AF_TRACE 16u /* Catch tracing */
3cdc3f3a 498#endif
46dde080 499#define AF_FOREGROUND 32u /* Quit server when client closes */
3cdc3f3a 500
501#ifndef NTRACE
502# define AF_ALLMSGS (AF_NOTE | AF_TRACE | AF_WARN)
503#else
504# define AF_ALLMSGS (AF_NOTE | AF_WARN)
505#endif
fd3cf232 506
410c8acf 507/*----- Global variables --------------------------------------------------*/
508
509extern sel_state sel; /* Global I/O event state */
52c03a2a 510extern group *gg; /* The group we work in */
de7bd20b 511extern size_t indexsz; /* Size of exponent for the group */
52c03a2a 512extern mp *kpriv; /* Our private key */
9317aa92 513extern ge *kpub; /* Our public key */
a4b808b0 514extern octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ], buf_u[PKBUFSZ];
42da2a58 515extern const tunnel_ops *tunnels[]; /* Table of tunnels (0-term) */
516extern const tunnel_ops *tun_default; /* Default tunnel to use */
410c8acf 517
518#ifndef NTRACE
519extern const trace_opt tr_opts[]; /* Trace options array */
520extern unsigned tr_flags; /* Trace options flags */
521#endif
522
8d0c7a83 523/*----- Other macros ------------------------------------------------------*/
524
525#define TIMER noise_timer(RAND_GLOBAL)
526
410c8acf 527/*----- Key management ----------------------------------------------------*/
528
de014da6 529/* --- @km_reload@ --- *
410c8acf 530 *
531 * Arguments: ---
532 *
533 * Returns: Zero if OK, nonzero to force reloading of keys.
534 *
de014da6 535 * Use: Checks the keyrings to see if they need reloading.
410c8acf 536 */
537
de014da6 538extern int km_reload(void);
410c8acf 539
540/* --- @km_init@ --- *
541 *
542 * Arguments: @const char *kr_priv@ = private keyring file
543 * @const char *kr_pub@ = public keyring file
544 * @const char *tag@ = tag to load
545 *
546 * Returns: ---
547 *
548 * Use: Initializes, and loads the private key.
549 */
550
551extern void km_init(const char */*kr_priv*/, const char */*kr_pub*/,
552 const char */*tag*/);
553
554/* --- @km_getpubkey@ --- *
555 *
556 * Arguments: @const char *tag@ = public key tag to load
52c03a2a 557 * @ge *kpub@ = where to put the public key
00e64b67 558 * @time_t *t_exp@ = where to put the expiry time
410c8acf 559 *
560 * Returns: Zero if OK, nonzero if it failed.
561 *
562 * Use: Fetches a public key from the keyring.
563 */
564
52c03a2a 565extern int km_getpubkey(const char */*tag*/, ge */*kpub*/,
00e64b67 566 time_t */*t_exp*/);
410c8acf 567
568/*----- Key exchange ------------------------------------------------------*/
569
570/* --- @kx_start@ --- *
571 *
572 * Arguments: @keyexch *kx@ = pointer to key exchange context
de014da6 573 * @int forcep@ = nonzero to ignore the quiet timer
410c8acf 574 *
575 * Returns: ---
576 *
577 * Use: Stimulates a key exchange. If a key exchage is in progress,
578 * a new challenge is sent (unless the quiet timer forbids
579 * this); if no exchange is in progress, one is commenced.
580 */
581
de014da6 582extern void kx_start(keyexch */*kx*/, int /*forcep*/);
410c8acf 583
832a2ab6 584/* --- @kx_message@ --- *
410c8acf 585 *
586 * Arguments: @keyexch *kx@ = pointer to key exchange context
832a2ab6 587 * @unsigned msg@ = the message code
588 * @buf *b@ = pointer to buffer containing the packet
410c8acf 589 *
590 * Returns: ---
591 *
832a2ab6 592 * Use: Reads a packet containing key exchange messages and handles
593 * it.
410c8acf 594 */
595
832a2ab6 596extern void kx_message(keyexch */*kx*/, unsigned /*msg*/, buf */*b*/);
410c8acf 597
598/* --- @kx_free@ --- *
599 *
600 * Arguments: @keyexch *kx@ = pointer to key exchange context
601 *
602 * Returns: ---
603 *
604 * Use: Frees everything in a key exchange context.
605 */
606
607extern void kx_free(keyexch */*kx*/);
608
609/* --- @kx_newkeys@ --- *
610 *
611 * Arguments: @keyexch *kx@ = pointer to key exchange context
612 *
613 * Returns: ---
614 *
615 * Use: Informs the key exchange module that its keys may have
616 * changed. If fetching the new keys fails, the peer will be
617 * destroyed, we log messages and struggle along with the old
618 * keys.
619 */
620
621extern void kx_newkeys(keyexch */*kx*/);
622
623/* --- @kx_init@ --- *
624 *
625 * Arguments: @keyexch *kx@ = pointer to key exchange context
626 * @peer *p@ = pointer to peer context
627 * @keyset **ks@ = pointer to keyset list
010e6f63 628 * @unsigned f@ = various useful flags
410c8acf 629 *
630 * Returns: Zero if OK, nonzero if it failed.
631 *
632 * Use: Initializes a key exchange module. The module currently
633 * contains no keys, and will attempt to initiate a key
634 * exchange.
635 */
636
010e6f63
MW
637extern int kx_init(keyexch */*kx*/, peer */*p*/,
638 keyset **/*ks*/, unsigned /*f*/);
410c8acf 639
640/*----- Keysets and symmetric cryptography --------------------------------*/
641
832a2ab6 642/* --- @ks_drop@ --- *
643 *
644 * Arguments: @keyset *ks@ = pointer to a keyset
645 *
646 * Returns: ---
647 *
648 * Use: Decrements a keyset's reference counter. If the counter hits
649 * zero, the keyset is freed.
650 */
651
652extern void ks_drop(keyset */*ks*/);
653
654/* --- @ks_gen@ --- *
655 *
656 * Arguments: @const void *k@ = pointer to key material
657 * @size_t x, y, z@ = offsets into key material (see below)
9466fafa 658 * @peer *p@ = pointer to peer information
832a2ab6 659 *
660 * Returns: A pointer to the new keyset.
661 *
662 * Use: Derives a new keyset from the given key material. The
663 * offsets @x@, @y@ and @z@ separate the key material into three
664 * parts. Between the @k@ and @k + x@ is `my' contribution to
665 * the key material; between @k + x@ and @k + y@ is `your'
666 * contribution; and between @k + y@ and @k + z@ is a shared
667 * value we made together. These are used to construct two
668 * pairs of symmetric keys. Each pair consists of an encryption
669 * key and a message authentication key. One pair is used for
670 * outgoing messages, the other for incoming messages.
671 *
672 * The new key is marked so that it won't be selected for output
673 * by @ksl_encrypt@. You can still encrypt data with it by
674 * calling @ks_encrypt@ directly.
675 */
676
677extern keyset *ks_gen(const void */*k*/,
9466fafa 678 size_t /*x*/, size_t /*y*/, size_t /*z*/,
679 peer */*p*/);
832a2ab6 680
681/* --- @ks_tregen@ --- *
682 *
683 * Arguments: @keyset *ks@ = pointer to a keyset
684 *
685 * Returns: The time at which moves ought to be made to replace this key.
686 */
687
688extern time_t ks_tregen(keyset */*ks*/);
689
690/* --- @ks_activate@ --- *
691 *
692 * Arguments: @keyset *ks@ = pointer to a keyset
693 *
694 * Returns: ---
695 *
696 * Use: Activates a keyset, so that it can be used for encrypting
697 * outgoing messages.
698 */
699
700extern void ks_activate(keyset */*ks*/);
701
702/* --- @ks_encrypt@ --- *
703 *
704 * Arguments: @keyset *ks@ = pointer to a keyset
7ed14135 705 * @unsigned ty@ = message type
832a2ab6 706 * @buf *b@ = pointer to input buffer
707 * @buf *bb@ = pointer to output buffer
708 *
a50f9a0e
MW
709 * Returns: Zero if successful; @KSERR_REGEN@ if we should negotiate a
710 * new key; @KSERR_NOKEYS@ if the key is not usable. Also
711 * returns zero if there was insufficient buffer (but the output
712 * buffer is broken in this case).
832a2ab6 713 *
714 * Use: Encrypts a block of data using the key. Note that the `key
715 * ought to be replaced' notification is only ever given once
716 * for each key. Also note that this call forces a keyset to be
717 * used even if it's marked as not for data output.
718 */
719
7ed14135 720extern int ks_encrypt(keyset */*ks*/, unsigned /*ty*/,
721 buf */*b*/, buf */*bb*/);
832a2ab6 722
723/* --- @ks_decrypt@ --- *
724 *
725 * Arguments: @keyset *ks@ = pointer to a keyset
7ed14135 726 * @unsigned ty@ = expected type code
832a2ab6 727 * @buf *b@ = pointer to an input buffer
728 * @buf *bb@ = pointer to an output buffer
729 *
a50f9a0e
MW
730 * Returns: Zero on success; @KSERR_DECRYPT@ on failure. Also returns
731 * zero if there was insufficient buffer (but the output buffer
732 * is broken in this case).
832a2ab6 733 *
734 * Use: Attempts to decrypt a message using a given key. Note that
735 * requesting decryption with a key directly won't clear a
736 * marking that it's not for encryption.
737 */
738
7ed14135 739extern int ks_decrypt(keyset */*ks*/, unsigned /*ty*/,
740 buf */*b*/, buf */*bb*/);
832a2ab6 741
742/* --- @ksl_free@ --- *
410c8acf 743 *
744 * Arguments: @keyset **ksroot@ = pointer to keyset list head
745 *
746 * Returns: ---
747 *
832a2ab6 748 * Use: Frees (releases references to) all of the keys in a keyset.
410c8acf 749 */
750
832a2ab6 751extern void ksl_free(keyset **/*ksroot*/);
410c8acf 752
832a2ab6 753/* --- @ksl_link@ --- *
410c8acf 754 *
755 * Arguments: @keyset **ksroot@ = pointer to keyset list head
832a2ab6 756 * @keyset *ks@ = pointer to a keyset
410c8acf 757 *
758 * Returns: ---
759 *
832a2ab6 760 * Use: Links a keyset into a list. A keyset can only be on one list
761 * at a time. Bad things happen otherwise.
410c8acf 762 */
763
832a2ab6 764extern void ksl_link(keyset **/*ksroot*/, keyset */*ks*/);
410c8acf 765
832a2ab6 766/* --- @ksl_prune@ --- *
410c8acf 767 *
768 * Arguments: @keyset **ksroot@ = pointer to keyset list head
410c8acf 769 *
832a2ab6 770 * Returns: ---
410c8acf 771 *
832a2ab6 772 * Use: Prunes the keyset list by removing keys which mustn't be used
773 * any more.
410c8acf 774 */
775
832a2ab6 776extern void ksl_prune(keyset **/*ksroot*/);
410c8acf 777
832a2ab6 778/* --- @ksl_encrypt@ --- *
410c8acf 779 *
780 * Arguments: @keyset **ksroot@ = pointer to keyset list head
7ed14135 781 * @unsigned ty@ = message type
410c8acf 782 * @buf *b@ = pointer to input buffer
783 * @buf *bb@ = pointer to output buffer
784 *
a50f9a0e
MW
785 * Returns: Zero if successful; @KSERR_REGEN@ if it's time to negotiate a
786 * new key; @KSERR_NOKEYS@ if there are no suitable keys
787 * available. Also returns zero if there was insufficient
788 * buffer space (but the output buffer is broken in this case).
410c8acf 789 *
790 * Use: Encrypts a packet.
791 */
792
7ed14135 793extern int ksl_encrypt(keyset **/*ksroot*/, unsigned /*ty*/,
794 buf */*b*/, buf */*bb*/);
410c8acf 795
832a2ab6 796/* --- @ksl_decrypt@ --- *
410c8acf 797 *
798 * Arguments: @keyset **ksroot@ = pointer to keyset list head
7ed14135 799 * @unsigned ty@ = expected type code
410c8acf 800 * @buf *b@ = pointer to input buffer
801 * @buf *bb@ = pointer to output buffer
802 *
a50f9a0e
MW
803 * Returns: Zero on success; @KSERR_DECRYPT@ on failure. Also returns
804 * zero if there was insufficient buffer (but the output buffer
805 * is broken in this case).
410c8acf 806 *
807 * Use: Decrypts a packet.
808 */
809
7ed14135 810extern int ksl_decrypt(keyset **/*ksroot*/, unsigned /*ty*/,
811 buf */*b*/, buf */*bb*/);
410c8acf 812
37941236 813/*----- Challenges --------------------------------------------------------*/
814
815/* --- @c_new@ --- *
816 *
817 * Arguments: @buf *b@ = where to put the challenge
818 *
819 * Returns: Zero if OK, nonzero on error.
820 *
821 * Use: Issues a new challenge.
822 */
823
824extern int c_new(buf */*b*/);
825
826/* --- @c_check@ --- *
827 *
828 * Arguments: @buf *b@ = where to find the challenge
829 *
830 * Returns: Zero if OK, nonzero if it didn't work.
831 *
832 * Use: Checks a challenge. On failure, the buffer is broken.
833 */
834
835extern int c_check(buf */*b*/);
836
410c8acf 837/*----- Administration interface ------------------------------------------*/
838
f43df819
MW
839#define A_END ((char *)0)
840
7f73baaf
MW
841/* --- @a_vformat@ --- *
842 *
843 * Arguments: @dstr *d@ = where to leave the formatted message
844 * @const char *fmt@ = pointer to format string
845 * @va_list ap@ = arguments in list
846 *
847 * Returns: ---
848 *
849 * Use: Main message token formatting driver. The arguments are
850 * interleaved formatting tokens and their parameters, finally
851 * terminated by an entry @A_END@.
852 *
853 * Tokens recognized:
854 *
855 * * "*..." ... -- pretokenized @dstr_putf@-like string
856 *
857 * * "?ADDR" SOCKADDR -- a socket address, to be converted
858 *
859 * * "?B64" BUFFER SIZE -- binary data to be base64-encoded
860 *
861 * * "?TOKENS" VECTOR -- null-terminated vector of tokens
862 *
863 * * "?PEER" PEER -- peer's name
864 *
865 * * "?ERRNO" ERRNO -- system error code
866 *
867 * * "[!]..." ... -- @dstr_putf@-like string as single token
868 */
869
870extern void a_vformat(dstr */*d*/, const char */*fmt*/, va_list /*ap*/);
871
410c8acf 872/* --- @a_warn@ --- *
873 *
874 * Arguments: @const char *fmt@ = pointer to format string
875 * @...@ = other arguments
876 *
877 * Returns: ---
878 *
879 * Use: Informs all admin connections of a warning.
880 */
881
882extern void a_warn(const char */*fmt*/, ...);
883
3cdc3f3a 884/* --- @a_notify@ --- *
885 *
886 * Arguments: @const char *fmt@ = pointer to format string
887 * @...@ = other arguments
888 *
889 * Returns: ---
890 *
891 * Use: Sends a notification to interested admin connections.
892 */
893
894extern void a_notify(const char */*fmt*/, ...);
895
410c8acf 896/* --- @a_create@ --- *
897 *
898 * Arguments: @int fd_in, fd_out@ = file descriptors to use
3cdc3f3a 899 * @unsigned f@ = initial flags to set
410c8acf 900 *
901 * Returns: ---
902 *
903 * Use: Creates a new admin connection.
904 */
905
3cdc3f3a 906extern void a_create(int /*fd_in*/, int /*fd_out*/, unsigned /*f*/);
410c8acf 907
908/* --- @a_quit@ --- *
909 *
910 * Arguments: ---
911 *
912 * Returns: ---
913 *
914 * Use: Shuts things down nicely.
915 */
916
917extern void a_quit(void);
918
c511e1f9
MW
919/* --- @a_preselect@ --- *
920 *
921 * Arguments: ---
922 *
923 * Returns: ---
924 *
925 * Use: Informs the admin module that we're about to select again,
926 * and that it should do cleanup things it has delayed until a
927 * `safe' time.
928 */
929
930extern void a_preselect(void);
931
410c8acf 932/* --- @a_daemon@ --- *
933 *
934 * Arguments: ---
935 *
936 * Returns: ---
937 *
938 * Use: Informs the admin module that it's a daemon.
939 */
940
941extern void a_daemon(void);
942
943/* --- @a_init@ --- *
944 *
945 * Arguments: @const char *sock@ = socket name to create
aa2405e8
MW
946 * @uid_t u@ = user to own the socket
947 * @gid_t g@ = group to own the socket
a9279e37 948 * @mode_t m@ = permissions to set on the socket
410c8acf 949 *
950 * Returns: ---
951 *
952 * Use: Creates the admin listening socket.
953 */
954
a9279e37
MW
955extern void a_init(const char */*sock*/,
956 uid_t /*u*/, gid_t /*g*/, mode_t /*m*/);
410c8acf 957
c8e02c8a
MW
958/*----- Mapping with addresses as keys ------------------------------------*/
959
960/* --- @am_create@ --- *
961 *
962 * Arguments: @addrmap *m@ = pointer to map
963 *
964 * Returns: ---
965 *
966 * Use: Create an address map, properly set up.
967 */
968
969extern void am_create(addrmap */*m*/);
970
971/* --- @am_destroy@ --- *
972 *
973 * Arguments: @addrmap *m@ = pointer to map
974 *
975 * Returns: ---
976 *
977 * Use: Destroy an address map, throwing away all the entries.
978 */
979
980extern void am_destroy(addrmap */*m*/);
981
982/* --- @am_find@ --- *
983 *
984 * Arguments: @addrmap *m@ = pointer to map
985 * @const addr *a@ = address to look up
986 * @size_t sz@ = size of block to allocate
987 * @unsigned *f@ = where to store flags
988 *
989 * Returns: Pointer to found item, or null.
990 *
991 * Use: Finds a record with the given IP address, set @*f@ nonzero
992 * and returns it. If @sz@ is zero, and no match was found,
993 * return null; otherwise allocate a new block of @sz@ bytes,
994 * clear @*f@ to zero and return the block pointer.
995 */
996
997extern void *am_find(addrmap */*m*/, const addr */*a*/,
998 size_t /*sz*/, unsigned */*f*/);
999
1000/* --- @am_remove@ --- *
1001 *
1002 * Arguments: @addrmap *m@ = pointer to map
1003 * @void *i@ = pointer to the item
1004 *
1005 * Returns: ---
1006 *
1007 * Use: Removes an item from the map.
1008 */
1009
1010extern void am_remove(addrmap */*m*/, void */*i*/);
1011
388e0319
MW
1012/*----- Privilege separation ----------------------------------------------*/
1013
1014/* --- @ps_trace@ --- *
1015 *
1016 * Arguments: @unsigned mask@ = trace mask to check
1017 * @const char *fmt@ = message format
1018 * @...@ = values for placeholders
1019 *
1020 * Returns: ---
1021 *
1022 * Use: Writes a trace message.
1023 */
1024
1025T( extern void ps_trace(unsigned /*mask*/, const char */*fmt*/, ...); )
1026
1027/* --- @ps_warn@ --- *
1028 *
1029 * Arguments: @const char *fmt@ = message format
1030 * @...@ = values for placeholders
1031 *
1032 * Returns: ---
1033 *
1034 * Use: Writes a warning message.
1035 */
1036
1037extern void ps_warn(const char */*fmt*/, ...);
1038
1039/* --- @ps_tunfd@ --- *
1040 *
1041 * Arguments: @const tunnel_ops *tops@ = pointer to tunnel operations
1042 * @char **ifn@ = where to put the interface name
1043 *
1044 * Returns: The file descriptor, or @-1@ on error.
1045 *
1046 * Use: Fetches a file descriptor for a tunnel driver.
1047 */
1048
1049extern int ps_tunfd(const tunnel_ops */*tops*/, char **/*ifn*/);
1050
1051/* --- @ps_split@ --- *
1052 *
1053 * Arguments: @int detachp@ = whether to detach the child from its terminal
1054 *
1055 * Returns: ---
1056 *
1057 * Use: Separates off the privileged tunnel-opening service from the
1058 * rest of the server.
1059 */
1060
1061extern void ps_split(int /*detachp*/);
1062
1063/* --- @ps_quit@ --- *
1064 *
1065 * Arguments: ---
1066 *
1067 * Returns: ---
1068 *
1069 * Use: Detaches from the helper process.
1070 */
1071
1072extern void ps_quit(void);
1073
410c8acf 1074/*----- Peer management ---------------------------------------------------*/
1075
1076/* --- @p_txstart@ --- *
1077 *
1078 * Arguments: @peer *p@ = pointer to peer block
1079 * @unsigned msg@ = message type code
1080 *
1081 * Returns: A pointer to a buffer to write to.
1082 *
1083 * Use: Starts sending to a peer. Only one send can happen at a
1084 * time.
1085 */
1086
1087extern buf *p_txstart(peer */*p*/, unsigned /*msg*/);
1088
1089/* --- @p_txend@ --- *
1090 *
1091 * Arguments: @peer *p@ = pointer to peer block
1092 *
1093 * Returns: ---
1094 *
1095 * Use: Sends a packet to the peer.
1096 */
1097
1098extern void p_txend(peer */*p*/);
1099
0ba8de86 1100/* --- @p_pingsend@ --- *
1101 *
1102 * Arguments: @peer *p@ = destination peer
1103 * @ping *pg@ = structure to fill in
1104 * @unsigned type@ = message type
1105 * @unsigned long timeout@ = how long to wait before giving up
1106 * @void (*func)(int, void *)@ = callback function
1107 * @void *arg@ = argument for callback
1108 *
1109 * Returns: Zero if successful, nonzero if it failed.
1110 *
1111 * Use: Sends a ping to a peer. Call @func@ with a nonzero argument
1112 * if we get an answer within the timeout, or zero if no answer.
1113 */
1114
1115extern int p_pingsend(peer */*p*/, ping */*pg*/, unsigned /*type*/,
1116 unsigned long /*timeout*/,
1117 void (*/*func*/)(int, void *), void */*arg*/);
1118
1119/* --- @p_pingdone@ --- *
1120 *
1121 * Arguments: @ping *p@ = ping structure
1122 * @int rc@ = return code to pass on
1123 *
1124 * Returns: ---
1125 *
1126 * Use: Disposes of a ping structure, maybe sending a notification.
1127 */
1128
1129extern void p_pingdone(ping */*p*/, int /*rc*/);
1130
37941236 1131/* --- @p_greet@ --- *
1132 *
1133 * Arguments: @peer *p@ = peer to send to
1134 * @const void *c@ = pointer to challenge
1135 * @size_t sz@ = size of challenge
1136 *
1137 * Returns: ---
1138 *
1139 * Use: Sends a greeting packet.
1140 */
1141
1142extern void p_greet(peer */*p*/, const void */*c*/, size_t /*sz*/);
1143
410c8acf 1144/* --- @p_tun@ --- *
1145 *
1146 * Arguments: @peer *p@ = pointer to peer block
1147 * @buf *b@ = buffer containing incoming packet
1148 *
1149 * Returns: ---
1150 *
1151 * Use: Handles a packet which needs to be sent to a peer.
1152 */
1153
1154extern void p_tun(peer */*p*/, buf */*b*/);
1155
de014da6 1156/* --- @p_keyreload@ --- *
1157 *
1158 * Arguments: ---
1159 *
1160 * Returns: ---
1161 *
1162 * Use: Forces a check of the daemon's keyring files.
1163 */
1164
1165extern void p_keyreload(void);
1166
410c8acf 1167/* --- @p_interval@ --- *
1168 *
1169 * Arguments: ---
1170 *
1171 * Returns: ---
1172 *
1173 * Use: Called periodically to do tidying.
1174 */
1175
1176extern void p_interval(void);
1177
832a2ab6 1178/* --- @p_stats@ --- *
1179 *
1180 * Arguments: @peer *p@ = pointer to a peer block
1181 *
1182 * Returns: A pointer to the peer's statistics.
1183 */
1184
1185extern stats *p_stats(peer */*p*/);
1186
410c8acf 1187/* --- @p_ifname@ --- *
1188 *
1189 * Arguments: @peer *p@ = pointer to a peer block
1190 *
1191 * Returns: A pointer to the peer's interface name.
1192 */
1193
1194extern const char *p_ifname(peer */*p*/);
1195
64cf2223
MW
1196/* --- @p_setifname@ --- *
1197 *
1198 * Arguments: @peer *p@ = pointer to a peer block
1199 * @const char *name@ = pointer to the new name
1200 *
1201 * Returns: ---
1202 *
1203 * Use: Changes the name held for a peer's interface.
1204 */
1205
1206extern void p_setifname(peer */*p*/, const char */*name*/);
1207
410c8acf 1208/* --- @p_addr@ --- *
1209 *
1210 * Arguments: @peer *p@ = pointer to a peer block
1211 *
1212 * Returns: A pointer to the peer's address.
1213 */
1214
1215extern const addr *p_addr(peer */*p*/);
1216
1217/* --- @p_init@ --- *
1218 *
767b36e2 1219 * Arguments: @struct in_addr addr@ = address to bind to
1220 * @unsigned port@ = port number to listen to
410c8acf 1221 *
1222 * Returns: ---
1223 *
1224 * Use: Initializes the peer system; creates the socket.
1225 */
1226
767b36e2 1227extern void p_init(struct in_addr /*addr*/, unsigned /*port*/);
410c8acf 1228
1229/* --- @p_port@ --- *
1230 *
1231 * Arguments: ---
1232 *
1233 * Returns: Port number used for socket.
1234 */
1235
1236unsigned p_port(void);
1237
1238/* --- @p_create@ --- *
1239 *
0ba8de86 1240 * Arguments: @peerspec *spec@ = information about this peer
410c8acf 1241 *
1242 * Returns: Pointer to the peer block, or null if it failed.
1243 *
1244 * Use: Creates a new named peer block. No peer is actually attached
1245 * by this point.
1246 */
1247
0ba8de86 1248extern peer *p_create(peerspec */*spec*/);
410c8acf 1249
1250/* --- @p_name@ --- *
1251 *
1252 * Arguments: @peer *p@ = pointer to a peer block
1253 *
1254 * Returns: A pointer to the peer's name.
060ca767 1255 *
1256 * Use: Equivalent to @p_spec(p)->name@.
410c8acf 1257 */
1258
1259extern const char *p_name(peer */*p*/);
1260
48b84569
MW
1261/* --- @p_tag@ --- *
1262 *
1263 * Arguments: @peer *p@ = pointer to a peer block
1264 *
1265 * Returns: A pointer to the peer's public key tag.
1266 */
1267
1268extern const char *p_tag(peer */*p*/);
1269
060ca767 1270/* --- @p_spec@ --- *
1271 *
1272 * Arguments: @peer *p@ = pointer to a peer block
1273 *
1274 * Returns: Pointer to the peer's specification
1275 */
1276
1277extern const peerspec *p_spec(peer */*p*/);
1278
c8e02c8a
MW
1279/* --- @p_findbyaddr@ --- *
1280 *
1281 * Arguments: @const addr *a@ = address to look up
1282 *
1283 * Returns: Pointer to the peer block, or null if not found.
1284 *
1285 * Use: Finds a peer by address.
1286 */
1287
1288extern peer *p_findbyaddr(const addr */*a*/);
1289
410c8acf 1290/* --- @p_find@ --- *
1291 *
1292 * Arguments: @const char *name@ = name to look up
1293 *
1294 * Returns: Pointer to the peer block, or null if not found.
1295 *
1296 * Use: Finds a peer by name.
1297 */
1298
1299extern peer *p_find(const char */*name*/);
1300
1301/* --- @p_destroy@ --- *
1302 *
1303 * Arguments: @peer *p@ = pointer to a peer
1304 *
1305 * Returns: ---
1306 *
1307 * Use: Destroys a peer.
1308 */
1309
1310extern void p_destroy(peer */*p*/);
1311
c8e02c8a
MW
1312/* --- @FOREACH_PEER@ --- *
1313 *
1314 * Arguments: @p@ = name to bind to each peer
1315 * @stuff@ = thing to do for each item
1316 *
1317 * Use: Does something for each current peer.
1318 */
1319
1320#define FOREACH_PEER(p, stuff) do { \
1321 peer_iter i_; \
1322 peer *p; \
46401b81 1323 for (p_mkiter(&i_); (p = p_next(&i_)) != 0; ) stuff \
c8e02c8a
MW
1324} while (0)
1325
1326/* --- @p_mkiter@ --- *
1327 *
1328 * Arguments: @peer_iter *i@ = pointer to an iterator
1329 *
1330 * Returns: ---
1331 *
1332 * Use: Initializes the iterator.
1333 */
1334
1335extern void p_mkiter(peer_iter */*i*/);
1336
1337/* --- @p_next@ --- *
1338 *
1339 * Arguments: @peer_iter *i@ = pointer to an iterator
410c8acf 1340 *
c8e02c8a 1341 * Returns: Next peer, or null if at the end.
410c8acf 1342 *
c8e02c8a 1343 * Use: Returns the next peer.
410c8acf 1344 */
1345
c8e02c8a 1346extern peer *p_next(peer_iter */*i*/);
410c8acf 1347
42da2a58 1348/*----- Tunnel drivers ----------------------------------------------------*/
410c8acf 1349
42da2a58 1350#ifdef TUN_LINUX
1351 extern const tunnel_ops tun_linux;
1352#endif
410c8acf 1353
42da2a58 1354#ifdef TUN_UNET
1355 extern const tunnel_ops tun_unet;
1356#endif
410c8acf 1357
42da2a58 1358#ifdef TUN_BSD
1359 extern const tunnel_ops tun_bsd;
1360#endif
410c8acf 1361
42da2a58 1362extern const tunnel_ops tun_slip;
410c8acf 1363
410c8acf 1364/*----- Other handy utilities ---------------------------------------------*/
1365
1366/* --- @mpstr@ --- *
1367 *
1368 * Arguments: @mp *m@ = a multiprecision integer
1369 *
1370 * Returns: A pointer to the integer's textual representation.
1371 *
1372 * Use: Converts a multiprecision integer to a string. Corrupts
a4b808b0 1373 * @buf_u@.
410c8acf 1374 */
1375
1376extern const char *mpstr(mp */*m*/);
1377
52c03a2a 1378/* --- @gestr@ --- *
1379 *
1380 * Arguments: @group *g@ = a group
1381 * @ge *x@ = a group element
1382 *
1383 * Returns: A pointer to the element's textual representation.
1384 *
1385 * Use: Converts a group element to a string. Corrupts
a4b808b0 1386 * @buf_u@.
52c03a2a 1387 */
1388
1389extern const char *gestr(group */*g*/, ge */*x*/);
1390
832a2ab6 1391/* --- @timestr@ --- *
1392 *
1393 * Arguments: @time_t t@ = a time to convert
1394 *
1395 * Returns: A pointer to a textual representation of the time.
1396 *
1397 * Use: Converts a time to a textual representation. Corrupts
a4b808b0 1398 * @buf_u@.
832a2ab6 1399 */
1400
1401extern const char *timestr(time_t /*t*/);
1402
42da2a58 1403/* --- @mystrieq@ --- *
1404 *
1405 * Arguments: @const char *x, *y@ = two strings
1406 *
1407 * Returns: True if @x@ and @y are equal, up to case.
1408 */
1409
1410extern int mystrieq(const char */*x*/, const char */*y*/);
1411
37941236 1412/* --- @seq_reset@ --- *
1413 *
1414 * Arguments: @seqwin *s@ = sequence-checking window
1415 *
1416 * Returns: ---
1417 *
1418 * Use: Resets a sequence number window.
1419 */
1420
1421extern void seq_reset(seqwin */*s*/);
1422
1423/* --- @seq_check@ --- *
1424 *
1425 * Arguments: @seqwin *s@ = sequence-checking window
1426 * @uint32 q@ = sequence number to check
f43df819 1427 * @const char *service@ = service to report message from
37941236 1428 *
1429 * Returns: A @SEQ_@ code.
1430 *
1431 * Use: Checks a sequence number against the window, updating things
1432 * as necessary.
1433 */
1434
f43df819 1435extern int seq_check(seqwin */*s*/, uint32 /*q*/, const char */*service*/);
37941236 1436
410c8acf 1437/*----- That's all, folks -------------------------------------------------*/
1438
1439#ifdef __cplusplus
1440 }
1441#endif
1442
1443#endif