chiark / gitweb /
Expunge revision histories in files.
[tripe] / tripe.h
CommitLineData
410c8acf 1/* -*-c-*-
2 *
b4e56668 3 * $Id: tripe.h,v 1.19 2004/04/08 01:36:17 mdw Exp $
410c8acf 4 *
5 * Main header file for TrIPE
6 *
7 * (c) 2001 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Trivial IP Encryption (TrIPE).
13 *
14 * TrIPE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * TrIPE is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with TrIPE; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
410c8acf 29#ifndef TRIPE_H
30#define TRIPE_H
31
32#ifdef __cplusplus
33 extern "C" {
34#endif
35
36/*----- Header files ------------------------------------------------------*/
37
73189848 38#include "config.h"
39
410c8acf 40#include <assert.h>
41#include <ctype.h>
42#include <errno.h>
43#include <signal.h>
44#include <stdarg.h>
45#include <stddef.h>
46#include <stdio.h>
47#include <stdlib.h>
48#include <string.h>
49#include <time.h>
50
51#include <sys/types.h>
52#include <sys/time.h>
53#include <unistd.h>
54#include <fcntl.h>
55#include <sys/stat.h>
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>
68#include <mLib/bres.h>
69#include <mLib/dstr.h>
70#include <mLib/env.h>
71#include <mLib/fdflags.h>
72#include <mLib/fwatch.h>
73#include <mLib/mdwopt.h>
74#include <mLib/quis.h>
75#include <mLib/report.h>
76#include <mLib/sel.h>
77#include <mLib/selbuf.h>
78#include <mLib/sig.h>
79#include <mLib/str.h>
80#include <mLib/sub.h>
81#include <mLib/trace.h>
82
165db1a8 83#include <catacomb/buf.h>
84
410c8acf 85#include <catacomb/gcipher.h>
86#include <catacomb/gmac.h>
87#include <catacomb/grand.h>
88#include <catacomb/key.h>
89#include <catacomb/paranoia.h>
90
410c8acf 91#include <catacomb/noise.h>
92#include <catacomb/rand.h>
410c8acf 93
94#include <catacomb/mp.h>
410c8acf 95#include <catacomb/mprand.h>
96#include <catacomb/dh.h>
52c03a2a 97#include <catacomb/ec.h>
98#include <catacomb/ec-keys.h>
99#include <catacomb/group.h>
410c8acf 100
165db1a8 101#include "tripe-protocol.h"
410c8acf 102#include "util.h"
103
104#undef sun
105
106/*----- Magic numbers -----------------------------------------------------*/
107
108/* --- Tunnel types --- */
109
110#define TUN_NOTDEF 0
111#define TUN_UNET 1
112#define TUN_BSD 2
37075862 113#define TUN_LINUX 3
410c8acf 114
115/* --- Trace flags --- */
116
117#define T_TUNNEL 1u
118#define T_PEER 2u
119#define T_PACKET 4u
120#define T_ADMIN 8u
121#define T_CRYPTO 16u
122#define T_KEYSET 32u
123#define T_KEYEXCH 64u
124#define T_KEYMGMT 128u
125
126#define T_ALL 255u
127
128/* --- Units --- */
129
130#define SEC(n) (n##u)
131#define MIN(n) (n##u * 60u)
132#define MEG(n) (n##ul * 1024ul * 1024ul)
133
134/* --- Other things --- */
135
136#define PKBUFSZ 65536
137
832a2ab6 138/*----- Cipher selections -------------------------------------------------*/
139
140#include <catacomb/blowfish.h>
141#include <catacomb/blowfish-cbc.h>
1d27afe6 142#include <catacomb/blowfish-counter.h>
832a2ab6 143#include <catacomb/rmd160.h>
144#include <catacomb/rmd160-hmac.h>
145
146#define CIPHER (&blowfish_cbc)
147#define MAC (&rmd160_hmac)
148
149#define HASH_CTX rmd160_ctx
150#define HASH_INIT rmd160_init
151#define HASH rmd160_hash
152#define HASH_STRING(c, s) HASH((c), s, sizeof(s))
153#define HASH_DONE rmd160_done
154#define HASHSZ RMD160_HASHSZ
155
1d27afe6 156#define MGF_CTX blowfish_counterctx
157#define MGF_INIT blowfish_counterinit
158#define MGF_CRYPT blowfish_counterencrypt
159
aeeb5611 160#define SEQSZ 4
161#define IVSZ BLOWFISH_BLKSZ
162#define MACSZ 10
410c8acf 163
aeeb5611 164/*----- Data structures ---------------------------------------------------*/
410c8acf 165
166/* --- Socket addresses --- *
167 *
168 * A magic union of supported socket addresses.
169 */
170
171typedef union addr {
172 struct sockaddr sa;
173 struct sockaddr_in sin;
174} addr;
175
176/* --- A symmetric keyset --- *
177 *
178 * A keyset contains a set of symmetric keys for encrypting and decrypting
179 * packets. Keysets are stored in a list, sorted in reverse order of
180 * creation, so that the most recent keyset (the one most likely to be used)
181 * is first.
182 *
183 * Each keyset has a time limit and a data limit. The keyset is destroyed
184 * when either it has existed for too long, or it has been used to encrypt
185 * too much data. New key exchanges are triggered when keys are close to
186 * expiry.
187 */
188
189typedef struct keyset {
190 struct keyset *next; /* Next active keyset in the list */
832a2ab6 191 unsigned ref; /* Reference count for keyset */
9466fafa 192 struct peer *p; /* Pointer to peer structure */
410c8acf 193 time_t t_exp; /* Expiry time for this keyset */
194 unsigned long sz_exp; /* Data limit for the keyset */
832a2ab6 195 T( unsigned seq; ) /* Sequence number for tracing */
196 unsigned f; /* Various useful flags */
197 gcipher *cin, *cout; /* Keyset ciphers for encryption */
198 gmac *min, *mout; /* Keyset MACs for integrity */
1484d822 199 uint32 oseq; /* Outbound sequence number */
200 uint32 iseq, iwin; /* Inbound sequence number */
410c8acf 201} keyset;
202
1484d822 203#define KS_SEQWINSZ 32 /* Bits in sequence number window */
204
832a2ab6 205#define KSF_LISTEN 1u /* Don't encrypt packets yet */
206#define KSF_LINK 2u /* Key is in a linked list */
207
410c8acf 208/* --- Key exchange --- *
209 *
210 * TrIPE uses the Wrestlers Protocol for its key exchange. The Wrestlers
211 * Protocol has a number of desirable features (e.g., perfect forward
212 * secrecy, and zero-knowledge authentication) which make it attractive for
213 * use in TrIPE. The Wrestlers Protocol was designed by Mark Wooding and
214 * Clive Jones.
215 */
216
832a2ab6 217#define KX_NCHAL 16u
218#define KX_THRESH 4u
219
220typedef struct kxchal {
221 struct keyexch *kx; /* Pointer back to key exchange */
52c03a2a 222 ge *c; /* Responder's challenge */
223 ge *r; /* My reply to the challenge */
832a2ab6 224 keyset *ks; /* Pointer to temporary keyset */
225 unsigned f; /* Various useful flags */
226 sel_timer t; /* Response timer for challenge */
227 octet hc[HASHSZ]; /* Hash of his challenge */
1d27afe6 228 mp *ck; /* The check value */
832a2ab6 229 octet hswrq_in[HASHSZ]; /* Inbound switch request message */
230 octet hswok_in[HASHSZ]; /* Inbound switch confirmation */
231 octet hswrq_out[HASHSZ]; /* Outbound switch request message */
232 octet hswok_out[HASHSZ]; /* Outbound switch confirmation */
233} kxchal;
234
410c8acf 235typedef struct keyexch {
410c8acf 236 struct peer *p; /* Pointer back to the peer */
832a2ab6 237 keyset **ks; /* Peer's list of keysets */
410c8acf 238 unsigned f; /* Various useful flags */
832a2ab6 239 unsigned s; /* Current state in exchange */
410c8acf 240 sel_timer t; /* Timer for next exchange */
52c03a2a 241 ge *kpub; /* Peer's public key */
00e64b67 242 time_t texp_kpub; /* Expiry time for public key */
832a2ab6 243 mp *alpha; /* My temporary secret */
52c03a2a 244 ge *c; /* My challenge */
245 ge *rx; /* The expected response */
832a2ab6 246 unsigned nr; /* Number of extant responses */
410c8acf 247 time_t t_valid; /* When this exchange goes bad */
832a2ab6 248 octet hc[HASHSZ]; /* Hash of my challenge */
249 kxchal *r[KX_NCHAL]; /* Array of challenges */
410c8acf 250} keyexch;
251
252#define KXF_TIMER 1u /* Waiting for a timer to go off */
00e64b67 253#define KXF_DEAD 2u /* The key-exchanger isn't up */
254#define KXF_PUBKEY 4u /* Key exchanger has a public key */
832a2ab6 255
256enum {
257 KXS_DEAD, /* Uninitialized state (magical) */
258 KXS_CHAL, /* Main answer-challenges state */
259 KXS_COMMIT, /* Committed: send switch request */
260 KXS_SWITCH /* Switched: send confirmation */
261};
410c8acf 262
263/* --- Tunnel structure --- *
264 *
265 * Used to maintain system-specific information about the tunnel interface.
266 */
267
110d564e 268#if TUN_TYPE == TUN_LINUX
269# include <linux/if.h>
270# include <linux/if_tun.h>
271#endif
272
410c8acf 273typedef struct tunnel {
37075862 274#if TUN_TYPE == TUN_UNET
410c8acf 275 sel_file f; /* Selector for Usernet device */
276 struct peer *p; /* Pointer to my peer */
37075862 277#elif TUN_TYPE == TUN_LINUX
278 sel_file f; /* Selector for TUN/TAP device */
279 struct peer *p; /* Pointer to my peer */
280 char ifn[IFNAMSIZ]; /* Interface name buffer */
1484d822 281#elif TUN_TYPE == TUN_BSD
282 sel_file f; /* Selector for tunnel device */
283 struct peer *p; /* Pointer to my peer */
284 unsigned n; /* Number of my tunnel device */
410c8acf 285#else
286# error "No support for this tunnel type"
287#endif
288} tunnel;
289
832a2ab6 290/* --- Peer statistics --- *
291 *
292 * Contains various interesting and not-so-interesting statistics about a
293 * peer. This is updated by various parts of the code. The format of the
294 * structure isn't considered private, and @p_stats@ returns a pointer to the
295 * statistics block for a given peer.
296 */
297
298typedef struct stats {
299 unsigned long sz_in, sz_out; /* Size of all data in and out */
300 unsigned long sz_kxin, sz_kxout; /* Size of key exchange messages */
301 unsigned long sz_ipin, sz_ipout; /* Size of encapsulated IP packets */
302 time_t t_start, t_last; /* Time peer created, last recv */
303 unsigned long n_reject; /* Number of rejected packets */
304 unsigned long n_in, n_out; /* Number of packets in and out */
305 unsigned long n_kxin, n_kxout; /* Number of key exchange packets */
306 unsigned long n_ipin, n_ipout; /* Number of encrypted packets */
307} stats;
308
410c8acf 309/* --- Peer structure --- *
310 *
311 * The main structure which glues everything else together.
312 */
313
314typedef struct peer {
315 struct peer *next, *prev; /* Links to next and previous */
316 char *name; /* Name of this peer */
317 tunnel t; /* Tunnel for local packets */
318 keyset *ks; /* List head for keysets */
410c8acf 319 buf b; /* Buffer for sending packets */
320 addr peer; /* Peer socket address */
321 size_t sasz; /* Socket address size */
832a2ab6 322 stats st; /* Statistics */
323 keyexch kx; /* Key exchange protocol block */
410c8acf 324} peer;
325
326/* --- Admin structure --- */
327
fd3cf232 328#define OBUFSZ 16384u
329
330typedef struct obuf {
331 struct obuf *next; /* Next buffer in list */
332 char *p_in, *p_out; /* Pointers into the buffer */
333 char buf[OBUFSZ]; /* The actual buffer */
334} obuf;
335
410c8acf 336typedef struct admin {
337 struct admin *next, *prev; /* Links to next and previous */
fd3cf232 338 unsigned f; /* Various useful flags */
410c8acf 339#ifndef NTRACE
340 unsigned seq; /* Sequence number for tracing */
341#endif
342 char *pname; /* Peer name to create */
343 char *paddr; /* Address string to resolve */
fd3cf232 344 obuf *o_head, *o_tail; /* Output buffer list */
345 selbuf b; /* Line buffer for commands */
346 sel_file w; /* Selector for write buffering */
410c8acf 347 bres_client r; /* Background resolver task */
348 sel_timer t; /* Timer for resolver */
349 addr peer; /* Address to set */
350 size_t sasz; /* Size of the address */
351} admin;
352
fd3cf232 353#define AF_DEAD 1u /* Destroy this admin block */
354#define AF_LOCK 2u /* Don't destroy it yet */
355
410c8acf 356/*----- Global variables --------------------------------------------------*/
357
358extern sel_state sel; /* Global I/O event state */
52c03a2a 359extern group *gg; /* The group we work in */
360extern mp *kpriv; /* Our private key */
832a2ab6 361extern octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ];
410c8acf 362
363#ifndef NTRACE
364extern const trace_opt tr_opts[]; /* Trace options array */
365extern unsigned tr_flags; /* Trace options flags */
366#endif
367
8d0c7a83 368/*----- Other macros ------------------------------------------------------*/
369
370#define TIMER noise_timer(RAND_GLOBAL)
371
410c8acf 372/*----- Key management ----------------------------------------------------*/
373
374/* --- @km_interval@ --- *
375 *
376 * Arguments: ---
377 *
378 * Returns: Zero if OK, nonzero to force reloading of keys.
379 *
380 * Use: Called on the interval timer to perform various useful jobs.
381 */
382
383extern int km_interval(void);
384
385/* --- @km_init@ --- *
386 *
387 * Arguments: @const char *kr_priv@ = private keyring file
388 * @const char *kr_pub@ = public keyring file
389 * @const char *tag@ = tag to load
390 *
391 * Returns: ---
392 *
393 * Use: Initializes, and loads the private key.
394 */
395
396extern void km_init(const char */*kr_priv*/, const char */*kr_pub*/,
397 const char */*tag*/);
398
399/* --- @km_getpubkey@ --- *
400 *
401 * Arguments: @const char *tag@ = public key tag to load
52c03a2a 402 * @ge *kpub@ = where to put the public key
00e64b67 403 * @time_t *t_exp@ = where to put the expiry time
410c8acf 404 *
405 * Returns: Zero if OK, nonzero if it failed.
406 *
407 * Use: Fetches a public key from the keyring.
408 */
409
52c03a2a 410extern int km_getpubkey(const char */*tag*/, ge */*kpub*/,
00e64b67 411 time_t */*t_exp*/);
410c8acf 412
413/*----- Key exchange ------------------------------------------------------*/
414
415/* --- @kx_start@ --- *
416 *
417 * Arguments: @keyexch *kx@ = pointer to key exchange context
418 *
419 * Returns: ---
420 *
421 * Use: Stimulates a key exchange. If a key exchage is in progress,
422 * a new challenge is sent (unless the quiet timer forbids
423 * this); if no exchange is in progress, one is commenced.
424 */
425
426extern void kx_start(keyexch */*kx*/);
427
832a2ab6 428/* --- @kx_message@ --- *
410c8acf 429 *
430 * Arguments: @keyexch *kx@ = pointer to key exchange context
832a2ab6 431 * @unsigned msg@ = the message code
432 * @buf *b@ = pointer to buffer containing the packet
410c8acf 433 *
434 * Returns: ---
435 *
832a2ab6 436 * Use: Reads a packet containing key exchange messages and handles
437 * it.
410c8acf 438 */
439
832a2ab6 440extern void kx_message(keyexch */*kx*/, unsigned /*msg*/, buf */*b*/);
410c8acf 441
442/* --- @kx_free@ --- *
443 *
444 * Arguments: @keyexch *kx@ = pointer to key exchange context
445 *
446 * Returns: ---
447 *
448 * Use: Frees everything in a key exchange context.
449 */
450
451extern void kx_free(keyexch */*kx*/);
452
453/* --- @kx_newkeys@ --- *
454 *
455 * Arguments: @keyexch *kx@ = pointer to key exchange context
456 *
457 * Returns: ---
458 *
459 * Use: Informs the key exchange module that its keys may have
460 * changed. If fetching the new keys fails, the peer will be
461 * destroyed, we log messages and struggle along with the old
462 * keys.
463 */
464
465extern void kx_newkeys(keyexch */*kx*/);
466
467/* --- @kx_init@ --- *
468 *
469 * Arguments: @keyexch *kx@ = pointer to key exchange context
470 * @peer *p@ = pointer to peer context
471 * @keyset **ks@ = pointer to keyset list
472 *
473 * Returns: Zero if OK, nonzero if it failed.
474 *
475 * Use: Initializes a key exchange module. The module currently
476 * contains no keys, and will attempt to initiate a key
477 * exchange.
478 */
479
480extern int kx_init(keyexch */*kx*/, peer */*p*/, keyset **/*ks*/);
481
482/*----- Keysets and symmetric cryptography --------------------------------*/
483
832a2ab6 484/* --- @ks_drop@ --- *
485 *
486 * Arguments: @keyset *ks@ = pointer to a keyset
487 *
488 * Returns: ---
489 *
490 * Use: Decrements a keyset's reference counter. If the counter hits
491 * zero, the keyset is freed.
492 */
493
494extern void ks_drop(keyset */*ks*/);
495
496/* --- @ks_gen@ --- *
497 *
498 * Arguments: @const void *k@ = pointer to key material
499 * @size_t x, y, z@ = offsets into key material (see below)
9466fafa 500 * @peer *p@ = pointer to peer information
832a2ab6 501 *
502 * Returns: A pointer to the new keyset.
503 *
504 * Use: Derives a new keyset from the given key material. The
505 * offsets @x@, @y@ and @z@ separate the key material into three
506 * parts. Between the @k@ and @k + x@ is `my' contribution to
507 * the key material; between @k + x@ and @k + y@ is `your'
508 * contribution; and between @k + y@ and @k + z@ is a shared
509 * value we made together. These are used to construct two
510 * pairs of symmetric keys. Each pair consists of an encryption
511 * key and a message authentication key. One pair is used for
512 * outgoing messages, the other for incoming messages.
513 *
514 * The new key is marked so that it won't be selected for output
515 * by @ksl_encrypt@. You can still encrypt data with it by
516 * calling @ks_encrypt@ directly.
517 */
518
519extern keyset *ks_gen(const void */*k*/,
9466fafa 520 size_t /*x*/, size_t /*y*/, size_t /*z*/,
521 peer */*p*/);
832a2ab6 522
523/* --- @ks_tregen@ --- *
524 *
525 * Arguments: @keyset *ks@ = pointer to a keyset
526 *
527 * Returns: The time at which moves ought to be made to replace this key.
528 */
529
530extern time_t ks_tregen(keyset */*ks*/);
531
532/* --- @ks_activate@ --- *
533 *
534 * Arguments: @keyset *ks@ = pointer to a keyset
535 *
536 * Returns: ---
537 *
538 * Use: Activates a keyset, so that it can be used for encrypting
539 * outgoing messages.
540 */
541
542extern void ks_activate(keyset */*ks*/);
543
544/* --- @ks_encrypt@ --- *
545 *
546 * Arguments: @keyset *ks@ = pointer to a keyset
7ed14135 547 * @unsigned ty@ = message type
832a2ab6 548 * @buf *b@ = pointer to input buffer
549 * @buf *bb@ = pointer to output buffer
550 *
551 * Returns: Zero if OK, nonzero if the key needs replacing. If the
552 * encryption failed, the output buffer is broken and zero is
553 * returned.
554 *
555 * Use: Encrypts a block of data using the key. Note that the `key
556 * ought to be replaced' notification is only ever given once
557 * for each key. Also note that this call forces a keyset to be
558 * used even if it's marked as not for data output.
559 */
560
7ed14135 561extern int ks_encrypt(keyset */*ks*/, unsigned /*ty*/,
562 buf */*b*/, buf */*bb*/);
832a2ab6 563
564/* --- @ks_decrypt@ --- *
565 *
566 * Arguments: @keyset *ks@ = pointer to a keyset
7ed14135 567 * @unsigned ty@ = expected type code
832a2ab6 568 * @buf *b@ = pointer to an input buffer
569 * @buf *bb@ = pointer to an output buffer
570 *
571 * Returns: Zero on success, or nonzero if there was some problem.
572 *
573 * Use: Attempts to decrypt a message using a given key. Note that
574 * requesting decryption with a key directly won't clear a
575 * marking that it's not for encryption.
576 */
577
7ed14135 578extern int ks_decrypt(keyset */*ks*/, unsigned /*ty*/,
579 buf */*b*/, buf */*bb*/);
832a2ab6 580
581/* --- @ksl_free@ --- *
410c8acf 582 *
583 * Arguments: @keyset **ksroot@ = pointer to keyset list head
584 *
585 * Returns: ---
586 *
832a2ab6 587 * Use: Frees (releases references to) all of the keys in a keyset.
410c8acf 588 */
589
832a2ab6 590extern void ksl_free(keyset **/*ksroot*/);
410c8acf 591
832a2ab6 592/* --- @ksl_link@ --- *
410c8acf 593 *
594 * Arguments: @keyset **ksroot@ = pointer to keyset list head
832a2ab6 595 * @keyset *ks@ = pointer to a keyset
410c8acf 596 *
597 * Returns: ---
598 *
832a2ab6 599 * Use: Links a keyset into a list. A keyset can only be on one list
600 * at a time. Bad things happen otherwise.
410c8acf 601 */
602
832a2ab6 603extern void ksl_link(keyset **/*ksroot*/, keyset */*ks*/);
410c8acf 604
832a2ab6 605/* --- @ksl_prune@ --- *
410c8acf 606 *
607 * Arguments: @keyset **ksroot@ = pointer to keyset list head
410c8acf 608 *
832a2ab6 609 * Returns: ---
410c8acf 610 *
832a2ab6 611 * Use: Prunes the keyset list by removing keys which mustn't be used
612 * any more.
410c8acf 613 */
614
832a2ab6 615extern void ksl_prune(keyset **/*ksroot*/);
410c8acf 616
832a2ab6 617/* --- @ksl_encrypt@ --- *
410c8acf 618 *
619 * Arguments: @keyset **ksroot@ = pointer to keyset list head
7ed14135 620 * @unsigned ty@ = message type
410c8acf 621 * @buf *b@ = pointer to input buffer
622 * @buf *bb@ = pointer to output buffer
623 *
624 * Returns: Nonzero if a new key is needed.
625 *
626 * Use: Encrypts a packet.
627 */
628
7ed14135 629extern int ksl_encrypt(keyset **/*ksroot*/, unsigned /*ty*/,
630 buf */*b*/, buf */*bb*/);
410c8acf 631
832a2ab6 632/* --- @ksl_decrypt@ --- *
410c8acf 633 *
634 * Arguments: @keyset **ksroot@ = pointer to keyset list head
7ed14135 635 * @unsigned ty@ = expected type code
410c8acf 636 * @buf *b@ = pointer to input buffer
637 * @buf *bb@ = pointer to output buffer
638 *
639 * Returns: Nonzero if the packet couldn't be decrypted.
640 *
641 * Use: Decrypts a packet.
642 */
643
7ed14135 644extern int ksl_decrypt(keyset **/*ksroot*/, unsigned /*ty*/,
645 buf */*b*/, buf */*bb*/);
410c8acf 646
647/*----- Administration interface ------------------------------------------*/
648
649/* --- @a_warn@ --- *
650 *
651 * Arguments: @const char *fmt@ = pointer to format string
652 * @...@ = other arguments
653 *
654 * Returns: ---
655 *
656 * Use: Informs all admin connections of a warning.
657 */
658
659extern void a_warn(const char */*fmt*/, ...);
660
661/* --- @a_create@ --- *
662 *
663 * Arguments: @int fd_in, fd_out@ = file descriptors to use
664 *
665 * Returns: ---
666 *
667 * Use: Creates a new admin connection.
668 */
669
670extern void a_create(int /*fd_in*/, int /*fd_out*/);
671
672/* --- @a_quit@ --- *
673 *
674 * Arguments: ---
675 *
676 * Returns: ---
677 *
678 * Use: Shuts things down nicely.
679 */
680
681extern void a_quit(void);
682
683/* --- @a_daemon@ --- *
684 *
685 * Arguments: ---
686 *
687 * Returns: ---
688 *
689 * Use: Informs the admin module that it's a daemon.
690 */
691
692extern void a_daemon(void);
693
694/* --- @a_init@ --- *
695 *
696 * Arguments: @const char *sock@ = socket name to create
697 *
698 * Returns: ---
699 *
700 * Use: Creates the admin listening socket.
701 */
702
703extern void a_init(const char */*sock*/);
704
705/*----- Peer management ---------------------------------------------------*/
706
707/* --- @p_txstart@ --- *
708 *
709 * Arguments: @peer *p@ = pointer to peer block
710 * @unsigned msg@ = message type code
711 *
712 * Returns: A pointer to a buffer to write to.
713 *
714 * Use: Starts sending to a peer. Only one send can happen at a
715 * time.
716 */
717
718extern buf *p_txstart(peer */*p*/, unsigned /*msg*/);
719
720/* --- @p_txend@ --- *
721 *
722 * Arguments: @peer *p@ = pointer to peer block
723 *
724 * Returns: ---
725 *
726 * Use: Sends a packet to the peer.
727 */
728
729extern void p_txend(peer */*p*/);
730
731/* --- @p_tun@ --- *
732 *
733 * Arguments: @peer *p@ = pointer to peer block
734 * @buf *b@ = buffer containing incoming packet
735 *
736 * Returns: ---
737 *
738 * Use: Handles a packet which needs to be sent to a peer.
739 */
740
741extern void p_tun(peer */*p*/, buf */*b*/);
742
743/* --- @p_interval@ --- *
744 *
745 * Arguments: ---
746 *
747 * Returns: ---
748 *
749 * Use: Called periodically to do tidying.
750 */
751
752extern void p_interval(void);
753
832a2ab6 754/* --- @p_stats@ --- *
755 *
756 * Arguments: @peer *p@ = pointer to a peer block
757 *
758 * Returns: A pointer to the peer's statistics.
759 */
760
761extern stats *p_stats(peer */*p*/);
762
410c8acf 763/* --- @p_ifname@ --- *
764 *
765 * Arguments: @peer *p@ = pointer to a peer block
766 *
767 * Returns: A pointer to the peer's interface name.
768 */
769
770extern const char *p_ifname(peer */*p*/);
771
772/* --- @p_addr@ --- *
773 *
774 * Arguments: @peer *p@ = pointer to a peer block
775 *
776 * Returns: A pointer to the peer's address.
777 */
778
779extern const addr *p_addr(peer */*p*/);
780
781/* --- @p_init@ --- *
782 *
767b36e2 783 * Arguments: @struct in_addr addr@ = address to bind to
784 * @unsigned port@ = port number to listen to
410c8acf 785 *
786 * Returns: ---
787 *
788 * Use: Initializes the peer system; creates the socket.
789 */
790
767b36e2 791extern void p_init(struct in_addr /*addr*/, unsigned /*port*/);
410c8acf 792
793/* --- @p_port@ --- *
794 *
795 * Arguments: ---
796 *
797 * Returns: Port number used for socket.
798 */
799
800unsigned p_port(void);
801
802/* --- @p_create@ --- *
803 *
804 * Arguments: @const char *name@ = name for this peer
805 * @struct sockaddr *sa@ = socket address of peer
806 * @size_t sz@ = size of socket address
807 *
808 * Returns: Pointer to the peer block, or null if it failed.
809 *
810 * Use: Creates a new named peer block. No peer is actually attached
811 * by this point.
812 */
813
814extern peer *p_create(const char */*name*/,
815 struct sockaddr */*sa*/, size_t /*sz*/);
816
817/* --- @p_name@ --- *
818 *
819 * Arguments: @peer *p@ = pointer to a peer block
820 *
821 * Returns: A pointer to the peer's name.
822 */
823
824extern const char *p_name(peer */*p*/);
825
826/* --- @p_find@ --- *
827 *
828 * Arguments: @const char *name@ = name to look up
829 *
830 * Returns: Pointer to the peer block, or null if not found.
831 *
832 * Use: Finds a peer by name.
833 */
834
835extern peer *p_find(const char */*name*/);
836
837/* --- @p_destroy@ --- *
838 *
839 * Arguments: @peer *p@ = pointer to a peer
840 *
841 * Returns: ---
842 *
843 * Use: Destroys a peer.
844 */
845
846extern void p_destroy(peer */*p*/);
847
848/* --- @p_first@, @p_next@ --- *
849 *
850 * Arguments: @peer *p@ = a peer block
851 *
852 * Returns: @peer_first@ returns the first peer in some ordering;
853 * @peer_next@ returns the peer following a given one in the
854 * same ordering. Null is returned for the end of the list.
855 */
856
857extern peer *p_first(void);
858extern peer *p_next(peer */*p*/);
859
860/*----- Tunnel interface --------------------------------------------------*/
861
862/* --- @tun_init@ --- *
863 *
864 * Arguments: ---
865 *
866 * Returns: ---
867 *
868 * Use: Initializes the tunneling system. Maybe this will require
869 * opening file descriptors or something.
870 */
871
872extern void tun_init(void);
873
874/* --- @tun_create@ --- *
875 *
876 * Arguments: @tunnel *t@ = pointer to tunnel block
877 * @peer *p@ = pointer to peer block
878 *
879 * Returns: Zero if it worked, nonzero on failure.
880 *
881 * Use: Initializes a new tunnel.
882 */
883
884extern int tun_create(tunnel */*t*/, peer */*p*/);
885
886/* --- @tun_ifname@ --- *
887 *
888 * Arguments: @tunnel *t@ = pointer to tunnel block
889 *
890 * Returns: A pointer to the tunnel's interface name.
891 */
892
893extern const char *tun_ifname(tunnel */*t*/);
894
895/* --- @tun_inject@ --- *
896 *
897 * Arguments: @tunnel *t@ = pointer to tunnel block
898 * @buf *b@ = buffer to send
899 *
900 * Returns: ---
901 *
902 * Use: Injects a packet into the local network stack.
903 */
904
905extern void tun_inject(tunnel */*t*/, buf */*b*/);
906
907/* --- @tun_destroy@ --- *
908 *
909 * Arguments: @tunnel *t@ = pointer to tunnel block
910 *
911 * Returns: ---
912 *
913 * Use: Destroys a tunnel.
914 */
915
916extern void tun_destroy(tunnel */*t*/);
917
410c8acf 918/*----- Other handy utilities ---------------------------------------------*/
919
920/* --- @mpstr@ --- *
921 *
922 * Arguments: @mp *m@ = a multiprecision integer
923 *
924 * Returns: A pointer to the integer's textual representation.
925 *
926 * Use: Converts a multiprecision integer to a string. Corrupts
832a2ab6 927 * @buf_t@.
410c8acf 928 */
929
930extern const char *mpstr(mp */*m*/);
931
52c03a2a 932/* --- @gestr@ --- *
933 *
934 * Arguments: @group *g@ = a group
935 * @ge *x@ = a group element
936 *
937 * Returns: A pointer to the element's textual representation.
938 *
939 * Use: Converts a group element to a string. Corrupts
940 * @buf_t@.
941 */
942
943extern const char *gestr(group */*g*/, ge */*x*/);
944
832a2ab6 945/* --- @timestr@ --- *
946 *
947 * Arguments: @time_t t@ = a time to convert
948 *
949 * Returns: A pointer to a textual representation of the time.
950 *
951 * Use: Converts a time to a textual representation. Corrupts
952 * @buf_t@.
953 */
954
955extern const char *timestr(time_t /*t*/);
956
410c8acf 957/*----- That's all, folks -------------------------------------------------*/
958
959#ifdef __cplusplus
960 }
961#endif
962
963#endif