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