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