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.
36 /*----- Header files ------------------------------------------------------*/
52 #include <sys/types.h>
58 #include <sys/socket.h>
60 #include <netinet/in.h>
61 #include <arpa/inet.h>
67 #include <mLib/alloc.h>
68 #include <mLib/arena.h>
69 #include <mLib/bres.h>
70 #include <mLib/dstr.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>
78 #include <mLib/selbuf.h>
82 #include <mLib/trace.h>
85 #include <catacomb/buf.h>
87 #include <catacomb/gcipher.h>
88 #include <catacomb/gmac.h>
89 #include <catacomb/grand.h>
90 #include <catacomb/key.h>
91 #include <catacomb/paranoia.h>
93 #include <catacomb/noise.h>
94 #include <catacomb/rand.h>
96 #include <catacomb/mp.h>
97 #include <catacomb/mprand.h>
98 #include <catacomb/dh.h>
99 #include <catacomb/ec.h>
100 #include <catacomb/ec-keys.h>
101 #include <catacomb/group.h>
103 #include "tripe-protocol.h"
108 /*----- Magic numbers -----------------------------------------------------*/
110 /* --- Trace flags --- */
118 #define T_KEYEXCH 64u
119 #define T_KEYMGMT 128u
125 #define SEC(n) (n##u)
126 #define MIN(n) (n##u * 60u)
127 #define MEG(n) (n##ul * 1024ul * 1024ul)
129 /* --- Other things --- */
131 #define PKBUFSZ 65536
133 /*----- Cipher selections -------------------------------------------------*/
135 typedef struct algswitch {
136 const gccipher *c; /* Symmetric encryption scheme */
137 const gccipher *mgf; /* Mask-generation function */
138 const gchash *h; /* Hash function */
139 const gcmac *m; /* Message authentication code */
140 size_t hashsz; /* Hash output size */
141 size_t tagsz; /* Length to truncate MAC tags */
142 size_t cksz, mksz; /* Key lengths for @c@ and @m@ */
145 extern algswitch algs;
147 #define MAXHASHSZ 64 /* Largest possible hash size */
149 #define HASH_STRING(h, s) GH_HASH((h), (s), sizeof(s))
151 /*----- Data structures ---------------------------------------------------*/
153 /* --- Socket addresses --- *
155 * A magic union of supported socket addresses.
160 struct sockaddr_in sin;
163 /* --- A symmetric keyset --- *
165 * A keyset contains a set of symmetric keys for encrypting and decrypting
166 * packets. Keysets are stored in a list, sorted in reverse order of
167 * creation, so that the most recent keyset (the one most likely to be used)
170 * Each keyset has a time limit and a data limit. The keyset is destroyed
171 * when either it has existed for too long, or it has been used to encrypt
172 * too much data. New key exchanges are triggered when keys are close to
176 typedef struct keyset {
177 struct keyset *next; /* Next active keyset in the list */
178 unsigned ref; /* Reference count for keyset */
179 struct peer *p; /* Pointer to peer structure */
180 time_t t_exp; /* Expiry time for this keyset */
181 unsigned long sz_exp; /* Data limit for the keyset */
182 T( unsigned seq; ) /* Sequence number for tracing */
183 unsigned f; /* Various useful flags */
184 gcipher *cin, *cout; /* Keyset ciphers for encryption */
185 size_t tagsz; /* Length to truncate MAC tags */
186 gmac *min, *mout; /* Keyset MACs for integrity */
187 uint32 oseq; /* Outbound sequence number */
188 uint32 iseq, iwin; /* Inbound sequence number */
191 #define KS_SEQWINSZ 32 /* Bits in sequence number window */
193 #define KSF_LISTEN 1u /* Don't encrypt packets yet */
194 #define KSF_LINK 2u /* Key is in a linked list */
196 /* --- Key exchange --- *
198 * TrIPE uses the Wrestlers Protocol for its key exchange. The Wrestlers
199 * Protocol has a number of desirable features (e.g., perfect forward
200 * secrecy, and zero-knowledge authentication) which make it attractive for
201 * use in TrIPE. The Wrestlers Protocol was designed by Mark Wooding and
208 typedef struct kxchal {
209 struct keyexch *kx; /* Pointer back to key exchange */
210 ge *c; /* Responder's challenge */
211 ge *r; /* My reply to the challenge */
212 keyset *ks; /* Pointer to temporary keyset */
213 unsigned f; /* Various useful flags */
214 sel_timer t; /* Response timer for challenge */
215 octet hc[MAXHASHSZ]; /* Hash of his challenge */
216 mp *ck; /* The check value */
217 octet hswrq_in[MAXHASHSZ]; /* Inbound switch request message */
218 octet hswok_in[MAXHASHSZ]; /* Inbound switch confirmation */
219 octet hswrq_out[MAXHASHSZ]; /* Outbound switch request message */
220 octet hswok_out[MAXHASHSZ]; /* Outbound switch confirmation */
223 typedef struct keyexch {
224 struct peer *p; /* Pointer back to the peer */
225 keyset **ks; /* Peer's list of keysets */
226 unsigned f; /* Various useful flags */
227 unsigned s; /* Current state in exchange */
228 sel_timer t; /* Timer for next exchange */
229 ge *kpub; /* Peer's public key */
230 time_t texp_kpub; /* Expiry time for public key */
231 mp *alpha; /* My temporary secret */
232 ge *c; /* My challenge */
233 ge *rx; /* The expected response */
234 unsigned nr; /* Number of extant responses */
235 time_t t_valid; /* When this exchange goes bad */
236 octet hc[MAXHASHSZ]; /* Hash of my challenge */
237 kxchal *r[KX_NCHAL]; /* Array of challenges */
240 #define KXF_TIMER 1u /* Waiting for a timer to go off */
241 #define KXF_DEAD 2u /* The key-exchanger isn't up */
242 #define KXF_PUBKEY 4u /* Key exchanger has a public key */
245 KXS_DEAD, /* Uninitialized state (magical) */
246 KXS_CHAL, /* Main answer-challenges state */
247 KXS_COMMIT, /* Committed: send switch request */
248 KXS_SWITCH /* Switched: send confirmation */
251 /* --- Tunnel structure --- *
253 * Used to maintain system-specific information about the tunnel interface.
256 typedef struct tunnel tunnel;
259 typedef struct tunnel_ops {
260 const char *name; /* Name of this tunnel driver */
261 void (*init)(void); /* Initializes the system */
262 tunnel *(*create)(struct peer */*p*/); /* Initializes a new tunnel */
263 const char *(*ifname)(tunnel */*t*/); /* Returns tunnel's interface name */
264 void (*inject)(tunnel */*t*/, buf */*b*/); /* Sends packet through if */
265 void (*destroy)(tunnel */*t*/); /* Destroys a tunnel */
268 #ifndef TUN_INTERNALS
269 struct tunnel { const tunnel_ops *ops; };
272 /* --- Peer statistics --- *
274 * Contains various interesting and not-so-interesting statistics about a
275 * peer. This is updated by various parts of the code. The format of the
276 * structure isn't considered private, and @p_stats@ returns a pointer to the
277 * statistics block for a given peer.
280 typedef struct stats {
281 unsigned long sz_in, sz_out; /* Size of all data in and out */
282 unsigned long sz_kxin, sz_kxout; /* Size of key exchange messages */
283 unsigned long sz_ipin, sz_ipout; /* Size of encapsulated IP packets */
284 time_t t_start, t_last, t_kx; /* Time peer created, last pk, kx */
285 unsigned long n_reject; /* Number of rejected packets */
286 unsigned long n_in, n_out; /* Number of packets in and out */
287 unsigned long n_kxin, n_kxout; /* Number of key exchange packets */
288 unsigned long n_ipin, n_ipout; /* Number of encrypted packets */
291 /* --- Peer structure --- *
293 * The main structure which glues everything else together.
296 typedef struct peerspec {
297 char *name; /* Peer's name */
298 const tunnel_ops *tops; /* Tunnel operations */
299 unsigned long t_ka; /* Keep alive interval */
300 addr sa; /* Socket address to speak to */
301 size_t sasz; /* Socket address size */
304 typedef struct peer {
305 struct peer *next, *prev; /* Links to next and previous */
306 struct ping *pings; /* Pings we're waiting for */
307 peerspec spec; /* Specifications for this peer */
308 tunnel *t; /* Tunnel for local packets */
309 keyset *ks; /* List head for keysets */
310 buf b; /* Buffer for sending packets */
311 stats st; /* Statistics */
312 keyexch kx; /* Key exchange protocol block */
313 sel_timer tka; /* Timer for keepalives */
316 typedef struct ping {
317 struct ping *next, *prev; /* Links to next and previous */
318 peer *p; /* Peer so we can free it */
319 unsigned msg; /* Kind of response expected */
320 uint32 id; /* Id so we can recognize response */
321 octet magic[32]; /* Some random data */
322 sel_timer t; /* Timeout for ping */
323 void (*func)(int /*rc*/, void */*arg*/); /* Function to call when done */
324 void *arg; /* Argument for callback */
335 /* --- Admin structure --- */
337 #define OBUFSZ 16384u
339 typedef struct obuf {
340 struct obuf *next; /* Next buffer in list */
341 char *p_in, *p_out; /* Pointers into the buffer */
342 char buf[OBUFSZ]; /* The actual buffer */
345 typedef struct oqueue {
346 obuf *hd, *tl; /* Head and tail pointers */
351 typedef struct admin_bgop {
352 struct admin_bgop *next, *prev; /* Links to next and previous */
353 struct admin *a; /* Owner job */
354 char *tag; /* Tag string for messages */
355 void (*cancel)(struct admin_bgop *); /* Destructor function */
358 typedef struct admin_addop {
359 admin_bgop bg; /* Background operation header */
360 peerspec peer; /* Peer pending creation */
361 char *paddr; /* Hostname to be resolved */
362 bres_client r; /* Background resolver task */
363 sel_timer t; /* Timer for resolver */
366 typedef struct admin_pingop {
367 admin_bgop bg; /* Background operation header */
368 ping ping; /* Ping pending response */
369 struct timeval pingtime; /* Time last ping was sent */
372 typedef struct admin {
373 struct admin *next, *prev; /* Links to next and previous */
374 unsigned f; /* Various useful flags */
375 unsigned ref; /* Reference counter */
377 unsigned seq; /* Sequence number for tracing */
379 oqueue out; /* Output buffer list */
380 oqueue delay; /* Delayed output buffer list */
381 admin_bgop *bg; /* Backgrounded operations */
382 selbuf b; /* Line buffer for commands */
383 sel_file w; /* Selector for write buffering */
386 #define AF_DEAD 1u /* Destroy this admin block */
387 #define AF_CLOSE 2u /* Client closed connection */
388 #define AF_NOTE 4u /* Catch notifications */
389 #define AF_WARN 8u /* Catch warning messages */
391 #define AF_TRACE 16u /* Catch tracing */
395 # define AF_ALLMSGS (AF_NOTE | AF_TRACE | AF_WARN)
397 # define AF_ALLMSGS (AF_NOTE | AF_WARN)
400 /*----- Global variables --------------------------------------------------*/
402 extern sel_state sel; /* Global I/O event state */
403 extern group *gg; /* The group we work in */
404 extern mp *kpriv; /* Our private key */
405 extern octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ];
406 extern const tunnel_ops *tunnels[]; /* Table of tunnels (0-term) */
407 extern const tunnel_ops *tun_default; /* Default tunnel to use */
410 extern const trace_opt tr_opts[]; /* Trace options array */
411 extern unsigned tr_flags; /* Trace options flags */
414 /*----- Other macros ------------------------------------------------------*/
416 #define TIMER noise_timer(RAND_GLOBAL)
418 /*----- Key management ----------------------------------------------------*/
420 /* --- @km_reload@ --- *
424 * Returns: Zero if OK, nonzero to force reloading of keys.
426 * Use: Checks the keyrings to see if they need reloading.
429 extern int km_reload(void);
431 /* --- @km_init@ --- *
433 * Arguments: @const char *kr_priv@ = private keyring file
434 * @const char *kr_pub@ = public keyring file
435 * @const char *tag@ = tag to load
439 * Use: Initializes, and loads the private key.
442 extern void km_init(const char */*kr_priv*/, const char */*kr_pub*/,
443 const char */*tag*/);
445 /* --- @km_getpubkey@ --- *
447 * Arguments: @const char *tag@ = public key tag to load
448 * @ge *kpub@ = where to put the public key
449 * @time_t *t_exp@ = where to put the expiry time
451 * Returns: Zero if OK, nonzero if it failed.
453 * Use: Fetches a public key from the keyring.
456 extern int km_getpubkey(const char */*tag*/, ge */*kpub*/,
459 /*----- Key exchange ------------------------------------------------------*/
461 /* --- @kx_start@ --- *
463 * Arguments: @keyexch *kx@ = pointer to key exchange context
464 * @int forcep@ = nonzero to ignore the quiet timer
468 * Use: Stimulates a key exchange. If a key exchage is in progress,
469 * a new challenge is sent (unless the quiet timer forbids
470 * this); if no exchange is in progress, one is commenced.
473 extern void kx_start(keyexch */*kx*/, int /*forcep*/);
475 /* --- @kx_message@ --- *
477 * Arguments: @keyexch *kx@ = pointer to key exchange context
478 * @unsigned msg@ = the message code
479 * @buf *b@ = pointer to buffer containing the packet
483 * Use: Reads a packet containing key exchange messages and handles
487 extern void kx_message(keyexch */*kx*/, unsigned /*msg*/, buf */*b*/);
489 /* --- @kx_free@ --- *
491 * Arguments: @keyexch *kx@ = pointer to key exchange context
495 * Use: Frees everything in a key exchange context.
498 extern void kx_free(keyexch */*kx*/);
500 /* --- @kx_newkeys@ --- *
502 * Arguments: @keyexch *kx@ = pointer to key exchange context
506 * Use: Informs the key exchange module that its keys may have
507 * changed. If fetching the new keys fails, the peer will be
508 * destroyed, we log messages and struggle along with the old
512 extern void kx_newkeys(keyexch */*kx*/);
514 /* --- @kx_init@ --- *
516 * Arguments: @keyexch *kx@ = pointer to key exchange context
517 * @peer *p@ = pointer to peer context
518 * @keyset **ks@ = pointer to keyset list
520 * Returns: Zero if OK, nonzero if it failed.
522 * Use: Initializes a key exchange module. The module currently
523 * contains no keys, and will attempt to initiate a key
527 extern int kx_init(keyexch */*kx*/, peer */*p*/, keyset **/*ks*/);
529 /*----- Keysets and symmetric cryptography --------------------------------*/
531 /* --- @ks_drop@ --- *
533 * Arguments: @keyset *ks@ = pointer to a keyset
537 * Use: Decrements a keyset's reference counter. If the counter hits
538 * zero, the keyset is freed.
541 extern void ks_drop(keyset */*ks*/);
543 /* --- @ks_gen@ --- *
545 * Arguments: @const void *k@ = pointer to key material
546 * @size_t x, y, z@ = offsets into key material (see below)
547 * @peer *p@ = pointer to peer information
549 * Returns: A pointer to the new keyset.
551 * Use: Derives a new keyset from the given key material. The
552 * offsets @x@, @y@ and @z@ separate the key material into three
553 * parts. Between the @k@ and @k + x@ is `my' contribution to
554 * the key material; between @k + x@ and @k + y@ is `your'
555 * contribution; and between @k + y@ and @k + z@ is a shared
556 * value we made together. These are used to construct two
557 * pairs of symmetric keys. Each pair consists of an encryption
558 * key and a message authentication key. One pair is used for
559 * outgoing messages, the other for incoming messages.
561 * The new key is marked so that it won't be selected for output
562 * by @ksl_encrypt@. You can still encrypt data with it by
563 * calling @ks_encrypt@ directly.
566 extern keyset *ks_gen(const void */*k*/,
567 size_t /*x*/, size_t /*y*/, size_t /*z*/,
570 /* --- @ks_tregen@ --- *
572 * Arguments: @keyset *ks@ = pointer to a keyset
574 * Returns: The time at which moves ought to be made to replace this key.
577 extern time_t ks_tregen(keyset */*ks*/);
579 /* --- @ks_activate@ --- *
581 * Arguments: @keyset *ks@ = pointer to a keyset
585 * Use: Activates a keyset, so that it can be used for encrypting
589 extern void ks_activate(keyset */*ks*/);
591 /* --- @ks_encrypt@ --- *
593 * Arguments: @keyset *ks@ = pointer to a keyset
594 * @unsigned ty@ = message type
595 * @buf *b@ = pointer to input buffer
596 * @buf *bb@ = pointer to output buffer
598 * Returns: Zero if OK, nonzero if the key needs replacing. If the
599 * encryption failed, the output buffer is broken and zero is
602 * Use: Encrypts a block of data using the key. Note that the `key
603 * ought to be replaced' notification is only ever given once
604 * for each key. Also note that this call forces a keyset to be
605 * used even if it's marked as not for data output.
608 extern int ks_encrypt(keyset */*ks*/, unsigned /*ty*/,
609 buf */*b*/, buf */*bb*/);
611 /* --- @ks_decrypt@ --- *
613 * Arguments: @keyset *ks@ = pointer to a keyset
614 * @unsigned ty@ = expected type code
615 * @buf *b@ = pointer to an input buffer
616 * @buf *bb@ = pointer to an output buffer
618 * Returns: Zero on success, or nonzero if there was some problem.
620 * Use: Attempts to decrypt a message using a given key. Note that
621 * requesting decryption with a key directly won't clear a
622 * marking that it's not for encryption.
625 extern int ks_decrypt(keyset */*ks*/, unsigned /*ty*/,
626 buf */*b*/, buf */*bb*/);
628 /* --- @ksl_free@ --- *
630 * Arguments: @keyset **ksroot@ = pointer to keyset list head
634 * Use: Frees (releases references to) all of the keys in a keyset.
637 extern void ksl_free(keyset **/*ksroot*/);
639 /* --- @ksl_link@ --- *
641 * Arguments: @keyset **ksroot@ = pointer to keyset list head
642 * @keyset *ks@ = pointer to a keyset
646 * Use: Links a keyset into a list. A keyset can only be on one list
647 * at a time. Bad things happen otherwise.
650 extern void ksl_link(keyset **/*ksroot*/, keyset */*ks*/);
652 /* --- @ksl_prune@ --- *
654 * Arguments: @keyset **ksroot@ = pointer to keyset list head
658 * Use: Prunes the keyset list by removing keys which mustn't be used
662 extern void ksl_prune(keyset **/*ksroot*/);
664 /* --- @ksl_encrypt@ --- *
666 * Arguments: @keyset **ksroot@ = pointer to keyset list head
667 * @unsigned ty@ = message type
668 * @buf *b@ = pointer to input buffer
669 * @buf *bb@ = pointer to output buffer
671 * Returns: Nonzero if a new key is needed.
673 * Use: Encrypts a packet.
676 extern int ksl_encrypt(keyset **/*ksroot*/, unsigned /*ty*/,
677 buf */*b*/, buf */*bb*/);
679 /* --- @ksl_decrypt@ --- *
681 * Arguments: @keyset **ksroot@ = pointer to keyset list head
682 * @unsigned ty@ = expected type code
683 * @buf *b@ = pointer to input buffer
684 * @buf *bb@ = pointer to output buffer
686 * Returns: Nonzero if the packet couldn't be decrypted.
688 * Use: Decrypts a packet.
691 extern int ksl_decrypt(keyset **/*ksroot*/, unsigned /*ty*/,
692 buf */*b*/, buf */*bb*/);
694 /*----- Administration interface ------------------------------------------*/
696 /* --- @a_warn@ --- *
698 * Arguments: @const char *fmt@ = pointer to format string
699 * @...@ = other arguments
703 * Use: Informs all admin connections of a warning.
706 extern void a_warn(const char */*fmt*/, ...);
708 /* --- @a_notify@ --- *
710 * Arguments: @const char *fmt@ = pointer to format string
711 * @...@ = other arguments
715 * Use: Sends a notification to interested admin connections.
718 extern void a_notify(const char */*fmt*/, ...);
720 /* --- @a_create@ --- *
722 * Arguments: @int fd_in, fd_out@ = file descriptors to use
723 * @unsigned f@ = initial flags to set
727 * Use: Creates a new admin connection.
730 extern void a_create(int /*fd_in*/, int /*fd_out*/, unsigned /*f*/);
732 /* --- @a_quit@ --- *
738 * Use: Shuts things down nicely.
741 extern void a_quit(void);
743 /* --- @a_daemon@ --- *
749 * Use: Informs the admin module that it's a daemon.
752 extern void a_daemon(void);
754 /* --- @a_init@ --- *
756 * Arguments: @const char *sock@ = socket name to create
760 * Use: Creates the admin listening socket.
763 extern void a_init(const char */*sock*/);
765 /*----- Peer management ---------------------------------------------------*/
767 /* --- @p_txstart@ --- *
769 * Arguments: @peer *p@ = pointer to peer block
770 * @unsigned msg@ = message type code
772 * Returns: A pointer to a buffer to write to.
774 * Use: Starts sending to a peer. Only one send can happen at a
778 extern buf *p_txstart(peer */*p*/, unsigned /*msg*/);
780 /* --- @p_txend@ --- *
782 * Arguments: @peer *p@ = pointer to peer block
786 * Use: Sends a packet to the peer.
789 extern void p_txend(peer */*p*/);
791 /* --- @p_pingsend@ --- *
793 * Arguments: @peer *p@ = destination peer
794 * @ping *pg@ = structure to fill in
795 * @unsigned type@ = message type
796 * @unsigned long timeout@ = how long to wait before giving up
797 * @void (*func)(int, void *)@ = callback function
798 * @void *arg@ = argument for callback
800 * Returns: Zero if successful, nonzero if it failed.
802 * Use: Sends a ping to a peer. Call @func@ with a nonzero argument
803 * if we get an answer within the timeout, or zero if no answer.
806 extern int p_pingsend(peer */*p*/, ping */*pg*/, unsigned /*type*/,
807 unsigned long /*timeout*/,
808 void (*/*func*/)(int, void *), void */*arg*/);
810 /* --- @p_pingdone@ --- *
812 * Arguments: @ping *p@ = ping structure
813 * @int rc@ = return code to pass on
817 * Use: Disposes of a ping structure, maybe sending a notification.
820 extern void p_pingdone(ping */*p*/, int /*rc*/);
824 * Arguments: @peer *p@ = pointer to peer block
825 * @buf *b@ = buffer containing incoming packet
829 * Use: Handles a packet which needs to be sent to a peer.
832 extern void p_tun(peer */*p*/, buf */*b*/);
834 /* --- @p_keyreload@ --- *
840 * Use: Forces a check of the daemon's keyring files.
843 extern void p_keyreload(void);
845 /* --- @p_interval@ --- *
851 * Use: Called periodically to do tidying.
854 extern void p_interval(void);
856 /* --- @p_stats@ --- *
858 * Arguments: @peer *p@ = pointer to a peer block
860 * Returns: A pointer to the peer's statistics.
863 extern stats *p_stats(peer */*p*/);
865 /* --- @p_ifname@ --- *
867 * Arguments: @peer *p@ = pointer to a peer block
869 * Returns: A pointer to the peer's interface name.
872 extern const char *p_ifname(peer */*p*/);
874 /* --- @p_addr@ --- *
876 * Arguments: @peer *p@ = pointer to a peer block
878 * Returns: A pointer to the peer's address.
881 extern const addr *p_addr(peer */*p*/);
883 /* --- @p_init@ --- *
885 * Arguments: @struct in_addr addr@ = address to bind to
886 * @unsigned port@ = port number to listen to
890 * Use: Initializes the peer system; creates the socket.
893 extern void p_init(struct in_addr /*addr*/, unsigned /*port*/);
895 /* --- @p_port@ --- *
899 * Returns: Port number used for socket.
902 unsigned p_port(void);
904 /* --- @p_create@ --- *
906 * Arguments: @peerspec *spec@ = information about this peer
908 * Returns: Pointer to the peer block, or null if it failed.
910 * Use: Creates a new named peer block. No peer is actually attached
914 extern peer *p_create(peerspec */*spec*/);
916 /* --- @p_name@ --- *
918 * Arguments: @peer *p@ = pointer to a peer block
920 * Returns: A pointer to the peer's name.
922 * Use: Equivalent to @p_spec(p)->name@.
925 extern const char *p_name(peer */*p*/);
927 /* --- @p_spec@ --- *
929 * Arguments: @peer *p@ = pointer to a peer block
931 * Returns: Pointer to the peer's specification
934 extern const peerspec *p_spec(peer */*p*/);
936 /* --- @p_find@ --- *
938 * Arguments: @const char *name@ = name to look up
940 * Returns: Pointer to the peer block, or null if not found.
942 * Use: Finds a peer by name.
945 extern peer *p_find(const char */*name*/);
947 /* --- @p_destroy@ --- *
949 * Arguments: @peer *p@ = pointer to a peer
953 * Use: Destroys a peer.
956 extern void p_destroy(peer */*p*/);
958 /* --- @p_first@, @p_next@ --- *
960 * Arguments: @peer *p@ = a peer block
962 * Returns: @peer_first@ returns the first peer in some ordering;
963 * @peer_next@ returns the peer following a given one in the
964 * same ordering. Null is returned for the end of the list.
967 extern peer *p_first(void);
968 extern peer *p_next(peer */*p*/);
970 /*----- Tunnel drivers ----------------------------------------------------*/
973 extern const tunnel_ops tun_linux;
977 extern const tunnel_ops tun_unet;
981 extern const tunnel_ops tun_bsd;
984 extern const tunnel_ops tun_slip;
986 /*----- Other handy utilities ---------------------------------------------*/
990 * Arguments: @mp *m@ = a multiprecision integer
992 * Returns: A pointer to the integer's textual representation.
994 * Use: Converts a multiprecision integer to a string. Corrupts
998 extern const char *mpstr(mp */*m*/);
1000 /* --- @gestr@ --- *
1002 * Arguments: @group *g@ = a group
1003 * @ge *x@ = a group element
1005 * Returns: A pointer to the element's textual representation.
1007 * Use: Converts a group element to a string. Corrupts
1011 extern const char *gestr(group */*g*/, ge */*x*/);
1013 /* --- @timestr@ --- *
1015 * Arguments: @time_t t@ = a time to convert
1017 * Returns: A pointer to a textual representation of the time.
1019 * Use: Converts a time to a textual representation. Corrupts
1023 extern const char *timestr(time_t /*t*/);
1025 /* --- @mystrieq@ --- *
1027 * Arguments: @const char *x, *y@ = two strings
1029 * Returns: True if @x@ and @y are equal, up to case.
1032 extern int mystrieq(const char */*x*/, const char */*y*/);
1034 /*----- That's all, folks -------------------------------------------------*/