3 * $Id: tripe.h,v 1.17 2003/10/15 09:30:18 mdw Exp $
5 * Main header file for TrIPE
7 * (c) 2001 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Trivial IP Encryption (TrIPE).
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.
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.
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.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.17 2003/10/15 09:30:18 mdw
33 * Add support for Ethereal protocol analysis.
35 * Revision 1.16 2003/07/13 11:19:49 mdw
36 * Incompatible protocol fix! Include message type code under MAC tag to
37 * prevent cut-and-paste from key-exchange messages to general packet
40 * Revision 1.15 2003/05/16 12:09:03 mdw
41 * Allow binding to a chosen address.
43 * Revision 1.14 2003/04/06 10:36:33 mdw
44 * Rearrange so as not to include Linux headers unless we need to.
46 * Revision 1.13 2003/04/06 10:26:35 mdw
47 * Report peer name on decrypt errors.
49 * Revision 1.12 2003/04/06 10:25:17 mdw
50 * Support Linux TUN/TAP device. Fix some bugs.
52 * Revision 1.11 2002/01/13 14:57:42 mdw
55 * Revision 1.10 2002/01/13 14:54:58 mdw
58 * Revision 1.9 2001/06/22 19:40:36 mdw
59 * Support expiry of other peers' public keys.
61 * Revision 1.8 2001/06/19 22:10:57 mdw
62 * Some more constants for the algorithms. Document the packet format
63 * change for non-malleability. Moved @buf@ definitions to separate header
66 * Revision 1.7 2001/03/03 12:07:08 mdw
67 * Rename word get and put functions now that there's 16-bit support.
69 * Revision 1.6 2001/02/19 19:11:09 mdw
70 * Output buffering on admin connections.
72 * Revision 1.5 2001/02/16 21:41:43 mdw
73 * Major changes. See source files for details.
75 * Revision 1.4 2001/02/05 19:56:37 mdw
76 * Sequence number protection, and BSD tunnels.
78 * Revision 1.3 2001/02/04 01:17:55 mdw
79 * Create a configuration header file to tidy up command lines.
81 * Revision 1.2 2001/02/03 22:40:29 mdw
82 * Put timer information into the entropy pool when packets are received
83 * and on similar events. Reseed the generator on the interval timer.
85 * Revision 1.1 2001/02/03 20:26:37 mdw
97 /*----- Header files ------------------------------------------------------*/
112 #include <sys/types.h>
113 #include <sys/time.h>
116 #include <sys/stat.h>
118 #include <sys/socket.h>
120 #include <netinet/in.h>
121 #include <arpa/inet.h>
127 #include <mLib/alloc.h>
128 #include <mLib/arena.h>
129 #include <mLib/bres.h>
130 #include <mLib/dstr.h>
131 #include <mLib/env.h>
132 #include <mLib/fdflags.h>
133 #include <mLib/fwatch.h>
134 #include <mLib/mdwopt.h>
135 #include <mLib/quis.h>
136 #include <mLib/report.h>
137 #include <mLib/sel.h>
138 #include <mLib/selbuf.h>
139 #include <mLib/sig.h>
140 #include <mLib/str.h>
141 #include <mLib/sub.h>
142 #include <mLib/trace.h>
144 #include <catacomb/buf.h>
146 #include <catacomb/gcipher.h>
147 #include <catacomb/gmac.h>
148 #include <catacomb/grand.h>
149 #include <catacomb/key.h>
150 #include <catacomb/paranoia.h>
152 #include <catacomb/noise.h>
153 #include <catacomb/rand.h>
155 #include <catacomb/mp.h>
156 #include <catacomb/mpmont.h>
157 #include <catacomb/mprand.h>
158 #include <catacomb/dh.h>
160 #include "tripe-protocol.h"
165 /*----- Magic numbers -----------------------------------------------------*/
167 /* --- Tunnel types --- */
174 /* --- Trace flags --- */
182 #define T_KEYEXCH 64u
183 #define T_KEYMGMT 128u
189 #define SEC(n) (n##u)
190 #define MIN(n) (n##u * 60u)
191 #define MEG(n) (n##ul * 1024ul * 1024ul)
193 /* --- Other things --- */
195 #define PKBUFSZ 65536
197 /*----- Cipher selections -------------------------------------------------*/
199 #include <catacomb/blowfish.h>
200 #include <catacomb/blowfish-cbc.h>
201 #include <catacomb/blowfish-counter.h>
202 #include <catacomb/rmd160.h>
203 #include <catacomb/rmd160-hmac.h>
205 #define CIPHER (&blowfish_cbc)
206 #define MAC (&rmd160_hmac)
208 #define HASH_CTX rmd160_ctx
209 #define HASH_INIT rmd160_init
210 #define HASH rmd160_hash
211 #define HASH_STRING(c, s) HASH((c), s, sizeof(s))
212 #define HASH_DONE rmd160_done
213 #define HASHSZ RMD160_HASHSZ
215 #define MGF_CTX blowfish_counterctx
216 #define MGF_INIT blowfish_counterinit
217 #define MGF_CRYPT blowfish_counterencrypt
220 #define IVSZ BLOWFISH_BLKSZ
223 /*----- Data structures ---------------------------------------------------*/
225 /* --- Socket addresses --- *
227 * A magic union of supported socket addresses.
232 struct sockaddr_in sin;
235 /* --- A symmetric keyset --- *
237 * A keyset contains a set of symmetric keys for encrypting and decrypting
238 * packets. Keysets are stored in a list, sorted in reverse order of
239 * creation, so that the most recent keyset (the one most likely to be used)
242 * Each keyset has a time limit and a data limit. The keyset is destroyed
243 * when either it has existed for too long, or it has been used to encrypt
244 * too much data. New key exchanges are triggered when keys are close to
248 typedef struct keyset {
249 struct keyset *next; /* Next active keyset in the list */
250 unsigned ref; /* Reference count for keyset */
251 struct peer *p; /* Pointer to peer structure */
252 time_t t_exp; /* Expiry time for this keyset */
253 unsigned long sz_exp; /* Data limit for the keyset */
254 T( unsigned seq; ) /* Sequence number for tracing */
255 unsigned f; /* Various useful flags */
256 gcipher *cin, *cout; /* Keyset ciphers for encryption */
257 gmac *min, *mout; /* Keyset MACs for integrity */
258 uint32 oseq; /* Outbound sequence number */
259 uint32 iseq, iwin; /* Inbound sequence number */
262 #define KS_SEQWINSZ 32 /* Bits in sequence number window */
264 #define KSF_LISTEN 1u /* Don't encrypt packets yet */
265 #define KSF_LINK 2u /* Key is in a linked list */
267 /* --- Key exchange --- *
269 * TrIPE uses the Wrestlers Protocol for its key exchange. The Wrestlers
270 * Protocol has a number of desirable features (e.g., perfect forward
271 * secrecy, and zero-knowledge authentication) which make it attractive for
272 * use in TrIPE. The Wrestlers Protocol was designed by Mark Wooding and
279 typedef struct kxchal {
280 struct keyexch *kx; /* Pointer back to key exchange */
281 mp *c; /* Responder's challenge */
282 mp *r; /* My reply to the challenge */
283 keyset *ks; /* Pointer to temporary keyset */
284 unsigned f; /* Various useful flags */
285 sel_timer t; /* Response timer for challenge */
286 octet hc[HASHSZ]; /* Hash of his challenge */
287 mp *ck; /* The check value */
288 octet hswrq_in[HASHSZ]; /* Inbound switch request message */
289 octet hswok_in[HASHSZ]; /* Inbound switch confirmation */
290 octet hswrq_out[HASHSZ]; /* Outbound switch request message */
291 octet hswok_out[HASHSZ]; /* Outbound switch confirmation */
294 typedef struct keyexch {
295 struct peer *p; /* Pointer back to the peer */
296 keyset **ks; /* Peer's list of keysets */
297 unsigned f; /* Various useful flags */
298 unsigned s; /* Current state in exchange */
299 sel_timer t; /* Timer for next exchange */
300 dh_pub kpub; /* Peer's public key */
301 time_t texp_kpub; /* Expiry time for public key */
302 mp *alpha; /* My temporary secret */
303 mp *c; /* My challenge */
304 mp *rx; /* The expected response */
305 unsigned nr; /* Number of extant responses */
306 time_t t_valid; /* When this exchange goes bad */
307 octet hc[HASHSZ]; /* Hash of my challenge */
308 kxchal *r[KX_NCHAL]; /* Array of challenges */
311 #define KXF_TIMER 1u /* Waiting for a timer to go off */
312 #define KXF_DEAD 2u /* The key-exchanger isn't up */
313 #define KXF_PUBKEY 4u /* Key exchanger has a public key */
316 KXS_DEAD, /* Uninitialized state (magical) */
317 KXS_CHAL, /* Main answer-challenges state */
318 KXS_COMMIT, /* Committed: send switch request */
319 KXS_SWITCH /* Switched: send confirmation */
322 /* --- Tunnel structure --- *
324 * Used to maintain system-specific information about the tunnel interface.
327 #if TUN_TYPE == TUN_LINUX
328 # include <linux/if.h>
329 # include <linux/if_tun.h>
332 typedef struct tunnel {
333 #if TUN_TYPE == TUN_UNET
334 sel_file f; /* Selector for Usernet device */
335 struct peer *p; /* Pointer to my peer */
336 #elif TUN_TYPE == TUN_LINUX
337 sel_file f; /* Selector for TUN/TAP device */
338 struct peer *p; /* Pointer to my peer */
339 char ifn[IFNAMSIZ]; /* Interface name buffer */
340 #elif TUN_TYPE == TUN_BSD
341 sel_file f; /* Selector for tunnel device */
342 struct peer *p; /* Pointer to my peer */
343 unsigned n; /* Number of my tunnel device */
345 # error "No support for this tunnel type"
349 /* --- Peer statistics --- *
351 * Contains various interesting and not-so-interesting statistics about a
352 * peer. This is updated by various parts of the code. The format of the
353 * structure isn't considered private, and @p_stats@ returns a pointer to the
354 * statistics block for a given peer.
357 typedef struct stats {
358 unsigned long sz_in, sz_out; /* Size of all data in and out */
359 unsigned long sz_kxin, sz_kxout; /* Size of key exchange messages */
360 unsigned long sz_ipin, sz_ipout; /* Size of encapsulated IP packets */
361 time_t t_start, t_last; /* Time peer created, last recv */
362 unsigned long n_reject; /* Number of rejected packets */
363 unsigned long n_in, n_out; /* Number of packets in and out */
364 unsigned long n_kxin, n_kxout; /* Number of key exchange packets */
365 unsigned long n_ipin, n_ipout; /* Number of encrypted packets */
368 /* --- Peer structure --- *
370 * The main structure which glues everything else together.
373 typedef struct peer {
374 struct peer *next, *prev; /* Links to next and previous */
375 char *name; /* Name of this peer */
376 tunnel t; /* Tunnel for local packets */
377 keyset *ks; /* List head for keysets */
378 buf b; /* Buffer for sending packets */
379 addr peer; /* Peer socket address */
380 size_t sasz; /* Socket address size */
381 stats st; /* Statistics */
382 keyexch kx; /* Key exchange protocol block */
385 /* --- Admin structure --- */
387 #define OBUFSZ 16384u
389 typedef struct obuf {
390 struct obuf *next; /* Next buffer in list */
391 char *p_in, *p_out; /* Pointers into the buffer */
392 char buf[OBUFSZ]; /* The actual buffer */
395 typedef struct admin {
396 struct admin *next, *prev; /* Links to next and previous */
397 unsigned f; /* Various useful flags */
399 unsigned seq; /* Sequence number for tracing */
401 char *pname; /* Peer name to create */
402 char *paddr; /* Address string to resolve */
403 obuf *o_head, *o_tail; /* Output buffer list */
404 selbuf b; /* Line buffer for commands */
405 sel_file w; /* Selector for write buffering */
406 bres_client r; /* Background resolver task */
407 sel_timer t; /* Timer for resolver */
408 addr peer; /* Address to set */
409 size_t sasz; /* Size of the address */
412 #define AF_DEAD 1u /* Destroy this admin block */
413 #define AF_LOCK 2u /* Don't destroy it yet */
415 /*----- Global variables --------------------------------------------------*/
417 extern sel_state sel; /* Global I/O event state */
418 extern dh_priv kpriv; /* Our private key */
419 extern mpmont mg; /* Montgomery context for DH group */
420 extern octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ];
423 extern const trace_opt tr_opts[]; /* Trace options array */
424 extern unsigned tr_flags; /* Trace options flags */
427 /*----- Other macros ------------------------------------------------------*/
429 #define TIMER noise_timer(RAND_GLOBAL)
431 /*----- Key management ----------------------------------------------------*/
433 /* --- @km_interval@ --- *
437 * Returns: Zero if OK, nonzero to force reloading of keys.
439 * Use: Called on the interval timer to perform various useful jobs.
442 extern int km_interval(void);
444 /* --- @km_init@ --- *
446 * Arguments: @const char *kr_priv@ = private keyring file
447 * @const char *kr_pub@ = public keyring file
448 * @const char *tag@ = tag to load
452 * Use: Initializes, and loads the private key.
455 extern void km_init(const char */*kr_priv*/, const char */*kr_pub*/,
456 const char */*tag*/);
458 /* --- @km_getpubkey@ --- *
460 * Arguments: @const char *tag@ = public key tag to load
461 * @dh_pub *kpub@ = where to put the public key
462 * @time_t *t_exp@ = where to put the expiry time
464 * Returns: Zero if OK, nonzero if it failed.
466 * Use: Fetches a public key from the keyring.
469 extern int km_getpubkey(const char */*tag*/, dh_pub */*kpub*/,
472 /*----- Key exchange ------------------------------------------------------*/
474 /* --- @kx_start@ --- *
476 * Arguments: @keyexch *kx@ = pointer to key exchange context
480 * Use: Stimulates a key exchange. If a key exchage is in progress,
481 * a new challenge is sent (unless the quiet timer forbids
482 * this); if no exchange is in progress, one is commenced.
485 extern void kx_start(keyexch */*kx*/);
487 /* --- @kx_message@ --- *
489 * Arguments: @keyexch *kx@ = pointer to key exchange context
490 * @unsigned msg@ = the message code
491 * @buf *b@ = pointer to buffer containing the packet
495 * Use: Reads a packet containing key exchange messages and handles
499 extern void kx_message(keyexch */*kx*/, unsigned /*msg*/, buf */*b*/);
501 /* --- @kx_free@ --- *
503 * Arguments: @keyexch *kx@ = pointer to key exchange context
507 * Use: Frees everything in a key exchange context.
510 extern void kx_free(keyexch */*kx*/);
512 /* --- @kx_newkeys@ --- *
514 * Arguments: @keyexch *kx@ = pointer to key exchange context
518 * Use: Informs the key exchange module that its keys may have
519 * changed. If fetching the new keys fails, the peer will be
520 * destroyed, we log messages and struggle along with the old
524 extern void kx_newkeys(keyexch */*kx*/);
526 /* --- @kx_init@ --- *
528 * Arguments: @keyexch *kx@ = pointer to key exchange context
529 * @peer *p@ = pointer to peer context
530 * @keyset **ks@ = pointer to keyset list
532 * Returns: Zero if OK, nonzero if it failed.
534 * Use: Initializes a key exchange module. The module currently
535 * contains no keys, and will attempt to initiate a key
539 extern int kx_init(keyexch */*kx*/, peer */*p*/, keyset **/*ks*/);
541 /*----- Keysets and symmetric cryptography --------------------------------*/
543 /* --- @ks_drop@ --- *
545 * Arguments: @keyset *ks@ = pointer to a keyset
549 * Use: Decrements a keyset's reference counter. If the counter hits
550 * zero, the keyset is freed.
553 extern void ks_drop(keyset */*ks*/);
555 /* --- @ks_gen@ --- *
557 * Arguments: @const void *k@ = pointer to key material
558 * @size_t x, y, z@ = offsets into key material (see below)
559 * @peer *p@ = pointer to peer information
561 * Returns: A pointer to the new keyset.
563 * Use: Derives a new keyset from the given key material. The
564 * offsets @x@, @y@ and @z@ separate the key material into three
565 * parts. Between the @k@ and @k + x@ is `my' contribution to
566 * the key material; between @k + x@ and @k + y@ is `your'
567 * contribution; and between @k + y@ and @k + z@ is a shared
568 * value we made together. These are used to construct two
569 * pairs of symmetric keys. Each pair consists of an encryption
570 * key and a message authentication key. One pair is used for
571 * outgoing messages, the other for incoming messages.
573 * The new key is marked so that it won't be selected for output
574 * by @ksl_encrypt@. You can still encrypt data with it by
575 * calling @ks_encrypt@ directly.
578 extern keyset *ks_gen(const void */*k*/,
579 size_t /*x*/, size_t /*y*/, size_t /*z*/,
582 /* --- @ks_tregen@ --- *
584 * Arguments: @keyset *ks@ = pointer to a keyset
586 * Returns: The time at which moves ought to be made to replace this key.
589 extern time_t ks_tregen(keyset */*ks*/);
591 /* --- @ks_activate@ --- *
593 * Arguments: @keyset *ks@ = pointer to a keyset
597 * Use: Activates a keyset, so that it can be used for encrypting
601 extern void ks_activate(keyset */*ks*/);
603 /* --- @ks_encrypt@ --- *
605 * Arguments: @keyset *ks@ = pointer to a keyset
606 * @unsigned ty@ = message type
607 * @buf *b@ = pointer to input buffer
608 * @buf *bb@ = pointer to output buffer
610 * Returns: Zero if OK, nonzero if the key needs replacing. If the
611 * encryption failed, the output buffer is broken and zero is
614 * Use: Encrypts a block of data using the key. Note that the `key
615 * ought to be replaced' notification is only ever given once
616 * for each key. Also note that this call forces a keyset to be
617 * used even if it's marked as not for data output.
620 extern int ks_encrypt(keyset */*ks*/, unsigned /*ty*/,
621 buf */*b*/, buf */*bb*/);
623 /* --- @ks_decrypt@ --- *
625 * Arguments: @keyset *ks@ = pointer to a keyset
626 * @unsigned ty@ = expected type code
627 * @buf *b@ = pointer to an input buffer
628 * @buf *bb@ = pointer to an output buffer
630 * Returns: Zero on success, or nonzero if there was some problem.
632 * Use: Attempts to decrypt a message using a given key. Note that
633 * requesting decryption with a key directly won't clear a
634 * marking that it's not for encryption.
637 extern int ks_decrypt(keyset */*ks*/, unsigned /*ty*/,
638 buf */*b*/, buf */*bb*/);
640 /* --- @ksl_free@ --- *
642 * Arguments: @keyset **ksroot@ = pointer to keyset list head
646 * Use: Frees (releases references to) all of the keys in a keyset.
649 extern void ksl_free(keyset **/*ksroot*/);
651 /* --- @ksl_link@ --- *
653 * Arguments: @keyset **ksroot@ = pointer to keyset list head
654 * @keyset *ks@ = pointer to a keyset
658 * Use: Links a keyset into a list. A keyset can only be on one list
659 * at a time. Bad things happen otherwise.
662 extern void ksl_link(keyset **/*ksroot*/, keyset */*ks*/);
664 /* --- @ksl_prune@ --- *
666 * Arguments: @keyset **ksroot@ = pointer to keyset list head
670 * Use: Prunes the keyset list by removing keys which mustn't be used
674 extern void ksl_prune(keyset **/*ksroot*/);
676 /* --- @ksl_encrypt@ --- *
678 * Arguments: @keyset **ksroot@ = pointer to keyset list head
679 * @unsigned ty@ = message type
680 * @buf *b@ = pointer to input buffer
681 * @buf *bb@ = pointer to output buffer
683 * Returns: Nonzero if a new key is needed.
685 * Use: Encrypts a packet.
688 extern int ksl_encrypt(keyset **/*ksroot*/, unsigned /*ty*/,
689 buf */*b*/, buf */*bb*/);
691 /* --- @ksl_decrypt@ --- *
693 * Arguments: @keyset **ksroot@ = pointer to keyset list head
694 * @unsigned ty@ = expected type code
695 * @buf *b@ = pointer to input buffer
696 * @buf *bb@ = pointer to output buffer
698 * Returns: Nonzero if the packet couldn't be decrypted.
700 * Use: Decrypts a packet.
703 extern int ksl_decrypt(keyset **/*ksroot*/, unsigned /*ty*/,
704 buf */*b*/, buf */*bb*/);
706 /*----- Administration interface ------------------------------------------*/
708 /* --- @a_warn@ --- *
710 * Arguments: @const char *fmt@ = pointer to format string
711 * @...@ = other arguments
715 * Use: Informs all admin connections of a warning.
718 extern void a_warn(const char */*fmt*/, ...);
720 /* --- @a_create@ --- *
722 * Arguments: @int fd_in, fd_out@ = file descriptors to use
726 * Use: Creates a new admin connection.
729 extern void a_create(int /*fd_in*/, int /*fd_out*/);
731 /* --- @a_quit@ --- *
737 * Use: Shuts things down nicely.
740 extern void a_quit(void);
742 /* --- @a_daemon@ --- *
748 * Use: Informs the admin module that it's a daemon.
751 extern void a_daemon(void);
753 /* --- @a_init@ --- *
755 * Arguments: @const char *sock@ = socket name to create
759 * Use: Creates the admin listening socket.
762 extern void a_init(const char */*sock*/);
764 /*----- Peer management ---------------------------------------------------*/
766 /* --- @p_txstart@ --- *
768 * Arguments: @peer *p@ = pointer to peer block
769 * @unsigned msg@ = message type code
771 * Returns: A pointer to a buffer to write to.
773 * Use: Starts sending to a peer. Only one send can happen at a
777 extern buf *p_txstart(peer */*p*/, unsigned /*msg*/);
779 /* --- @p_txend@ --- *
781 * Arguments: @peer *p@ = pointer to peer block
785 * Use: Sends a packet to the peer.
788 extern void p_txend(peer */*p*/);
792 * Arguments: @peer *p@ = pointer to peer block
793 * @buf *b@ = buffer containing incoming packet
797 * Use: Handles a packet which needs to be sent to a peer.
800 extern void p_tun(peer */*p*/, buf */*b*/);
802 /* --- @p_interval@ --- *
808 * Use: Called periodically to do tidying.
811 extern void p_interval(void);
813 /* --- @p_stats@ --- *
815 * Arguments: @peer *p@ = pointer to a peer block
817 * Returns: A pointer to the peer's statistics.
820 extern stats *p_stats(peer */*p*/);
822 /* --- @p_ifname@ --- *
824 * Arguments: @peer *p@ = pointer to a peer block
826 * Returns: A pointer to the peer's interface name.
829 extern const char *p_ifname(peer */*p*/);
831 /* --- @p_addr@ --- *
833 * Arguments: @peer *p@ = pointer to a peer block
835 * Returns: A pointer to the peer's address.
838 extern const addr *p_addr(peer */*p*/);
840 /* --- @p_init@ --- *
842 * Arguments: @struct in_addr addr@ = address to bind to
843 * @unsigned port@ = port number to listen to
847 * Use: Initializes the peer system; creates the socket.
850 extern void p_init(struct in_addr /*addr*/, unsigned /*port*/);
852 /* --- @p_port@ --- *
856 * Returns: Port number used for socket.
859 unsigned p_port(void);
861 /* --- @p_create@ --- *
863 * Arguments: @const char *name@ = name for this peer
864 * @struct sockaddr *sa@ = socket address of peer
865 * @size_t sz@ = size of socket address
867 * Returns: Pointer to the peer block, or null if it failed.
869 * Use: Creates a new named peer block. No peer is actually attached
873 extern peer *p_create(const char */*name*/,
874 struct sockaddr */*sa*/, size_t /*sz*/);
876 /* --- @p_name@ --- *
878 * Arguments: @peer *p@ = pointer to a peer block
880 * Returns: A pointer to the peer's name.
883 extern const char *p_name(peer */*p*/);
885 /* --- @p_find@ --- *
887 * Arguments: @const char *name@ = name to look up
889 * Returns: Pointer to the peer block, or null if not found.
891 * Use: Finds a peer by name.
894 extern peer *p_find(const char */*name*/);
896 /* --- @p_destroy@ --- *
898 * Arguments: @peer *p@ = pointer to a peer
902 * Use: Destroys a peer.
905 extern void p_destroy(peer */*p*/);
907 /* --- @p_first@, @p_next@ --- *
909 * Arguments: @peer *p@ = a peer block
911 * Returns: @peer_first@ returns the first peer in some ordering;
912 * @peer_next@ returns the peer following a given one in the
913 * same ordering. Null is returned for the end of the list.
916 extern peer *p_first(void);
917 extern peer *p_next(peer */*p*/);
919 /*----- Tunnel interface --------------------------------------------------*/
921 /* --- @tun_init@ --- *
927 * Use: Initializes the tunneling system. Maybe this will require
928 * opening file descriptors or something.
931 extern void tun_init(void);
933 /* --- @tun_create@ --- *
935 * Arguments: @tunnel *t@ = pointer to tunnel block
936 * @peer *p@ = pointer to peer block
938 * Returns: Zero if it worked, nonzero on failure.
940 * Use: Initializes a new tunnel.
943 extern int tun_create(tunnel */*t*/, peer */*p*/);
945 /* --- @tun_ifname@ --- *
947 * Arguments: @tunnel *t@ = pointer to tunnel block
949 * Returns: A pointer to the tunnel's interface name.
952 extern const char *tun_ifname(tunnel */*t*/);
954 /* --- @tun_inject@ --- *
956 * Arguments: @tunnel *t@ = pointer to tunnel block
957 * @buf *b@ = buffer to send
961 * Use: Injects a packet into the local network stack.
964 extern void tun_inject(tunnel */*t*/, buf */*b*/);
966 /* --- @tun_destroy@ --- *
968 * Arguments: @tunnel *t@ = pointer to tunnel block
972 * Use: Destroys a tunnel.
975 extern void tun_destroy(tunnel */*t*/);
977 /*----- Other handy utilities ---------------------------------------------*/
981 * Arguments: @mp *m@ = a multiprecision integer
983 * Returns: A pointer to the integer's textual representation.
985 * Use: Converts a multiprecision integer to a string. Corrupts
989 extern const char *mpstr(mp */*m*/);
991 /* --- @timestr@ --- *
993 * Arguments: @time_t t@ = a time to convert
995 * Returns: A pointer to a textual representation of the time.
997 * Use: Converts a time to a textual representation. Corrupts
1001 extern const char *timestr(time_t /*t*/);
1003 /*----- That's all, folks -------------------------------------------------*/